-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Saba
committed
May 25, 2024
1 parent
f35dae6
commit 556b35b
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django_rpyc.decorators import register | ||
from django_rpyc.server import DjangoRpycService | ||
|
||
|
||
def test_register_with_name(): | ||
@register("my_service") | ||
class MyService: | ||
pass | ||
|
||
assert "my_service" in DjangoRpycService.MAPPING | ||
assert DjangoRpycService.MAPPING["my_service"] == MyService | ||
|
||
|
||
def test_register_without_name(): | ||
@register | ||
class MyService: | ||
pass | ||
|
||
assert "myservice" in DjangoRpycService.MAPPING | ||
assert DjangoRpycService.MAPPING["myservice"] == MyService | ||
|
||
|
||
def test_register_with_non_string_name(): | ||
@register(123) | ||
class MyService: | ||
pass | ||
|
||
assert "myservice" in DjangoRpycService.MAPPING | ||
assert DjangoRpycService.MAPPING[123] == MyService | ||
|
||
|
||
def test_register_with_name_printing(capfd): | ||
@register("my_service") | ||
class MyService: | ||
pass | ||
|
||
captured = capfd.readouterr() | ||
assert "Registered: Name: my_service, Class: MyService" in captured.out | ||
|
||
|
||
def test_register_without_name_printing(capfd): | ||
@register | ||
class MyService: | ||
pass | ||
|
||
captured = capfd.readouterr() | ||
assert "Registered: Name: myservice, Class: MyService" in captured.out | ||
|
||
|
||
def test_register_with_non_string_name_printing(capfd): | ||
@register(123) | ||
class MyService: | ||
pass | ||
|
||
captured = capfd.readouterr() | ||
assert "Registered: Name: 123, Class: MyService" in captured.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from django_rpyc.server import DjangoRpycService | ||
|
||
|
||
def test_add_service(): | ||
|
||
class MyService: | ||
pass | ||
|
||
name = "my_service" | ||
service = MyService | ||
|
||
result = DjangoRpycService.add_service(name, service) | ||
|
||
assert result == service | ||
assert name in DjangoRpycService.MAPPING | ||
assert DjangoRpycService.MAPPING[name] == service | ||
|
||
|
||
def test_get_service_names(): | ||
|
||
class MyService: | ||
pass | ||
|
||
DjangoRpycService.MAPPING.clear() | ||
|
||
name = "my_service" | ||
service = MyService | ||
|
||
DjangoRpycService.add_service(name, service) | ||
|
||
expected_names = [name] | ||
obj = DjangoRpycService() | ||
actual_names = obj.exposed_get_service_names() | ||
|
||
assert actual_names == expected_names | ||
|
||
|
||
def test_exposed_use_existing_service(): | ||
class MyService: | ||
pass | ||
|
||
DjangoRpycService.MAPPING.clear() | ||
|
||
name = "my_service" | ||
service = MyService | ||
|
||
DjangoRpycService.add_service(name, service) | ||
|
||
obj = DjangoRpycService() | ||
result = obj.exposed_use(name) | ||
|
||
assert isinstance(result, MyService) | ||
|
||
|
||
def test_exposed_use_nonexistent_service(): | ||
DjangoRpycService.MAPPING.clear() | ||
|
||
name = "nonexistent_service" | ||
|
||
obj = DjangoRpycService() | ||
|
||
try: | ||
obj.exposed_use(name) | ||
assert False, "Expected ValueError to be raised" | ||
except ValueError as e: | ||
assert str(e) == f"Service {name} not found" |