-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ozgurkara/unit-test
unit test
- Loading branch information
Showing
4 changed files
with
128 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
[run] | ||
relative_files = True | ||
|
||
[report] | ||
exclude_lines = | ||
pragma: no cover | ||
@abstract | ||
def __init__ |
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
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
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,44 @@ | ||
from pydiator_core.serializer import BaseSerializer, SerializerFactory, Serializer | ||
from tests.base_test_case import BaseTestCase, TestResponse | ||
|
||
|
||
class TestSerializerFactory(BaseTestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_set_serializer(self): | ||
# Given | ||
class TestSerializerObj(BaseSerializer): | ||
|
||
def dumps(self, obj): | ||
return "" | ||
|
||
def loads(self, obj): | ||
return "test" | ||
|
||
def deserialize(self, obj): | ||
return self.loads(self.dumps(obj)) | ||
|
||
test_serializer = TestSerializerObj() | ||
SerializerFactory.set_serializer(serializer=test_serializer) | ||
|
||
test_response = TestResponse(True) | ||
|
||
# When | ||
response = test_response.to_json() | ||
|
||
# Then | ||
assert response == "test" | ||
assert test_serializer == SerializerFactory.get_serializer() | ||
|
||
def test_serializer_when_does_not_call_set(self): | ||
# Given | ||
|
||
# When | ||
current_serializer = SerializerFactory.get_serializer() | ||
|
||
# Then | ||
assert isinstance(current_serializer, Serializer) |