-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests for basic fields
- Loading branch information
Showing
7 changed files
with
139 additions
and
7 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
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,23 @@ | ||
import pytest | ||
|
||
from protean.fields.basic import Boolean | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value,expected", | ||
[ | ||
(True, True), | ||
(False, False), | ||
(1, True), | ||
(0, False), | ||
("t", True), | ||
("f", False), | ||
("True", True), | ||
("False", False), | ||
(1.0, True), | ||
(0.0, False), | ||
], | ||
) | ||
def test_boolean_cast_to_type(value, expected): | ||
field = Boolean() | ||
assert field._cast_to_type(value) == expected |
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,21 @@ | ||
from datetime import datetime, timezone | ||
|
||
from protean.fields import Method | ||
|
||
|
||
def utc_now(): | ||
return datetime.now(timezone.utc) | ||
|
||
|
||
def test_method_repr_and_str(): | ||
method_obj1 = Method("fake_method") | ||
method_obj2 = Method("fake_method", required=True) | ||
method_obj4 = Method("fake_method", required=True, default=utc_now) | ||
|
||
assert repr(method_obj1) == str(method_obj1) == "Method()" | ||
assert repr(method_obj2) == str(method_obj2) == "Method(required=True)" | ||
assert ( | ||
repr(method_obj4) | ||
== str(method_obj4) | ||
== "Method(required=True, default=utc_now)" | ||
) |
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,21 @@ | ||
from protean.fields import Nested | ||
|
||
|
||
def test_nested_field_repr_and_str(): | ||
nested_obj1 = Nested("schema1") | ||
nested_obj2 = Nested("schema1", many=True, required=True) | ||
nested_obj3 = Nested("schema1", default={"name": "John Doe"}) | ||
nested_obj4 = Nested("schema1", required=True, default={"name": "John Doe"}) | ||
|
||
assert repr(nested_obj1) == str(nested_obj1) == "Nested('schema1')" | ||
assert repr(nested_obj2) == str(nested_obj2) == "Nested('schema1', required=True)" | ||
assert ( | ||
repr(nested_obj3) | ||
== str(nested_obj3) | ||
== "Nested('schema1', default={'name': 'John Doe'})" | ||
) | ||
assert ( | ||
repr(nested_obj4) | ||
== str(nested_obj4) | ||
== "Nested('schema1', required=True, default={'name': 'John Doe'})" | ||
) |
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