-
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.
🧪 tests: implement unit tests for value objects including Uuid, Bytes…
…, Float, String, Boolean, Integer
- Loading branch information
1 parent
4b2219a
commit becea14
Showing
30 changed files
with
870 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,7 @@ | ||
from .test_string_uuid_value_object import StringUuidValueObject | ||
from .test_uuid_value_object import UuidValueObject | ||
|
||
__all__ = ( | ||
'StringUuidValueObject', | ||
'UuidValueObject', | ||
) |
42 changes: 42 additions & 0 deletions
42
tests/usables/identifiers/test_string_uuid_value_object.py
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,42 @@ | ||
""" | ||
Test StringUuidValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import StringMother, StringUuidMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.identifiers import StringUuidValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_uuid_value_object_happy_path() -> None: | ||
""" | ||
Test StringUuidValueObject value object happy path. | ||
""" | ||
uuid_value = StringUuidValueObject(value=StringUuidMother.create()) | ||
|
||
assert type(uuid_value.value) is str | ||
|
||
|
||
@mark.unit_testing | ||
def test_uuid_value_object_invalid_value() -> None: | ||
""" | ||
Test StringUuidValueObject value object raises ValueError when value is not an UUID. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match=r'StringUuidValueObject value <<<.*>>> is not a valid UUID.', | ||
): | ||
StringUuidValueObject(value=StringMother.create()) | ||
|
||
|
||
@mark.unit_testing | ||
def test_uuid_value_object_invalid_type() -> None: | ||
""" | ||
Test StringUuidValueObject value object raises TypeError when value is not an UUID. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'StringValueObject value <<<.*>>> must be a string. Got <<<.*>>> type.', | ||
): | ||
StringUuidValueObject(value=StringUuidMother.invalid_type()) |
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,32 @@ | ||
""" | ||
Test UuidValueObject value object. | ||
""" | ||
|
||
from uuid import UUID | ||
|
||
from object_mother_pattern.mothers import UuidMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.identifiers import UuidValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_uuid_value_object_happy_path() -> None: | ||
""" | ||
Test UuidValueObject value object happy path. | ||
""" | ||
uuid_value = UuidValueObject(value=UuidMother.create()) | ||
|
||
assert type(uuid_value.value) is UUID | ||
|
||
|
||
@mark.unit_testing | ||
def test_uuid_value_object_invalid_type() -> None: | ||
""" | ||
Test UuidValueObject value object raises TypeError when value is not an UUID. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'UuidValueObject value <<<.*>>> must be a UUID. Got <<<.*>>> type.', | ||
): | ||
UuidValueObject(value=UuidMother.invalid_type()) |
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions
30
tests/usables/primitives/boolean/test_boolean_value_object.py
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,30 @@ | ||
""" | ||
Test BooleanValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import BooleanMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import BooleanValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_boolean_value_object_happy_path() -> None: | ||
""" | ||
Test BooleanValueObject value object happy path. | ||
""" | ||
boolean_value = BooleanValueObject(value=BooleanMother.create()) | ||
|
||
assert type(boolean_value.value) is bool | ||
|
||
|
||
@mark.unit_testing | ||
def test_boolean_value_object_invalid_type() -> None: | ||
""" | ||
Test BooleanValueObject value object raises TypeError when value is not boolean. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'BooleanValueObject value <<<.*>>> must be a boolean. Got <<<.*>>> type.', | ||
): | ||
BooleanValueObject(value=BooleanMother.invalid_type()) |
42 changes: 42 additions & 0 deletions
42
tests/usables/primitives/boolean/test_false_value_object.py
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,42 @@ | ||
""" | ||
Test FalseValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import BooleanMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import FalseValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_false_value_object_happy_path() -> None: | ||
""" | ||
Test FalseValueObject value object happy path. | ||
""" | ||
boolean_value = FalseValueObject(value=BooleanMother.create(value=False)) | ||
|
||
assert not boolean_value.value | ||
|
||
|
||
@mark.unit_testing | ||
def test_false_value_object_invalid_value() -> None: | ||
""" | ||
Test FalseValueObject value object raises ValueError when value is not False. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match='FalseValueObject value <<<True>>> must be false.', | ||
): | ||
FalseValueObject(value=BooleanMother.create(value=True)) | ||
|
||
|
||
@mark.unit_testing | ||
def test_false_value_object_invalid_type() -> None: | ||
""" | ||
Test FalseValueObject value object raises TypeError when value is not boolean. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'BooleanValueObject value <<<.*>>> must be a boolean. Got <<<.*>>> type.', | ||
): | ||
FalseValueObject(value=BooleanMother.invalid_type()) |
42 changes: 42 additions & 0 deletions
42
tests/usables/primitives/boolean/test_true_value_object.py
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,42 @@ | ||
""" | ||
Test TrueValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import BooleanMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import TrueValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_true_value_object_happy_path() -> None: | ||
""" | ||
Test TrueValueObject value object happy path. | ||
""" | ||
boolean_value = TrueValueObject(value=BooleanMother.create(value=True)) | ||
|
||
assert boolean_value.value | ||
|
||
|
||
@mark.unit_testing | ||
def test_true_value_object_invalid_value() -> None: | ||
""" | ||
Test TrueValueObject value object raises ValueError when value is not True. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match='TrueValueObject value <<<False>>> must be true.', | ||
): | ||
TrueValueObject(value=BooleanMother.create(value=False)) | ||
|
||
|
||
@mark.unit_testing | ||
def test_true_value_object_invalid_type() -> None: | ||
""" | ||
Test TrueValueObject value object raises TypeError when value is not boolean. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'BooleanValueObject value <<<.*>>> must be a boolean. Got <<<.*>>> type.', | ||
): | ||
TrueValueObject(value=BooleanMother.invalid_type()) |
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,30 @@ | ||
""" | ||
Test BytesValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import BytesMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import BytesValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_bytes_value_object_happy_path() -> None: | ||
""" | ||
Test BytesValueObject value object happy path. | ||
""" | ||
bytes_value = BytesValueObject(value=BytesMother.create()) | ||
|
||
assert type(bytes_value.value) is bytes | ||
|
||
|
||
@mark.unit_testing | ||
def test_bytes_value_object_invalid_type() -> None: | ||
""" | ||
Test BytesValueObject value object raises TypeError when value is not bytes. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'BytesValueObject value <<<.*>>> must be bytes. Got <<<.*>>> type.', | ||
): | ||
BytesValueObject(value=BytesMother.invalid_type()) |
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,30 @@ | ||
""" | ||
Test FloatValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import FloatMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import FloatValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_float_value_object_happy_path() -> None: | ||
""" | ||
Test FloatValueObject value object happy path. | ||
""" | ||
float_value = FloatValueObject(value=FloatMother.create()) | ||
|
||
assert type(float_value.value) is float | ||
|
||
|
||
@mark.unit_testing | ||
def test_float_value_object_invalid_type() -> None: | ||
""" | ||
Test FloatValueObject value object raises TypeError when value is not float. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'FloatValueObject value <<<.*>>> must be a float. Got <<<.*>>> type.', | ||
): | ||
FloatValueObject(value=FloatMother.invalid_type()) |
43 changes: 43 additions & 0 deletions
43
tests/usables/primitives/float/test_negative_float_value_object.py
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,43 @@ | ||
""" | ||
Test NegativeFloatValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import FloatMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import NegativeFloatValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_negative_float_value_object_happy_path() -> None: | ||
""" | ||
Test NegativeFloatValueObject value object happy path. | ||
""" | ||
float_value = NegativeFloatValueObject(value=FloatMother.negative()) | ||
|
||
assert type(float_value.value) is float | ||
assert float_value.value < 0 | ||
|
||
|
||
@mark.unit_testing | ||
def test_negative_float_value_object_invalid_value() -> None: | ||
""" | ||
Test NegativeFloatValueObject value object raises ValueError when value is not negative. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match=r'NegativeFloatValueObject value <<<.*>>> must be a negative float.', | ||
): | ||
NegativeFloatValueObject(value=FloatMother.create(min=0)) | ||
|
||
|
||
@mark.unit_testing | ||
def test_negative_float_value_object_invalid_type() -> None: | ||
""" | ||
Test NegativeFloatValueObject value object raises TypeError when value is not float. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'FloatValueObject value <<<.*>>> must be a float. Got <<<.*>>> type.', | ||
): | ||
NegativeFloatValueObject(value=FloatMother.invalid_type()) |
43 changes: 43 additions & 0 deletions
43
tests/usables/primitives/float/test_positive_float_value_object.py
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,43 @@ | ||
""" | ||
Test PositiveFloatValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import FloatMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import PositiveFloatValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_positive_float_value_object_happy_path() -> None: | ||
""" | ||
Test PositiveFloatValueObject value object happy path. | ||
""" | ||
float_value = PositiveFloatValueObject(value=FloatMother.positive()) | ||
|
||
assert type(float_value.value) is float | ||
assert float_value.value > 0 | ||
|
||
|
||
@mark.unit_testing | ||
def test_positive_float_value_object_invalid_value() -> None: | ||
""" | ||
Test PositiveFloatValueObject value object raises ValueError when value is not positive. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match=r'PositiveFloatValueObject value <<<.*>>> must be a positive float.', | ||
): | ||
PositiveFloatValueObject(value=FloatMother.create(max=0)) | ||
|
||
|
||
@mark.unit_testing | ||
def test_positive_float_value_object_invalid_type() -> None: | ||
""" | ||
Test PositiveFloatValueObject value object raises TypeError when value is not float. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'FloatValueObject value <<<.*>>> must be a float. Got <<<.*>>> type.', | ||
): | ||
PositiveFloatValueObject(value=FloatMother.invalid_type()) |
Empty file.
42 changes: 42 additions & 0 deletions
42
tests/usables/primitives/integer/test_even_integer_value_object.py
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,42 @@ | ||
""" | ||
Test EvenIntegerValueObject value object. | ||
""" | ||
|
||
from object_mother_pattern.mothers import IntegerMother | ||
from pytest import mark, raises as assert_raises | ||
|
||
from value_object_pattern.usables.primitives import EvenIntegerValueObject | ||
|
||
|
||
@mark.unit_testing | ||
def test_even_integer_value_object_happy_path() -> None: | ||
""" | ||
Test EvenIntegerValueObject value object happy path. | ||
""" | ||
integer_value = EvenIntegerValueObject(value=IntegerMother.create() * 2) | ||
|
||
assert type(integer_value.value) is int | ||
|
||
|
||
@mark.unit_testing | ||
def test_even_integer_value_object_invalid_value() -> None: | ||
""" | ||
Test EvenIntegerValueObject value object raises ValueError when value is not an even number. | ||
""" | ||
with assert_raises( | ||
expected_exception=ValueError, | ||
match=r'EvenIntegerValueObject value <<<.*>>> must be an even number.', | ||
): | ||
EvenIntegerValueObject(value=IntegerMother.create() * 2 + 1) | ||
|
||
|
||
@mark.unit_testing | ||
def test_even_integer_value_object_invalid_type() -> None: | ||
""" | ||
Test EvenIntegerValueObject value object raises TypeError when value is not integer. | ||
""" | ||
with assert_raises( | ||
expected_exception=TypeError, | ||
match=r'IntegerValueObject value <<<.*>>> must be an integer. Got <<<.*>>> type.', | ||
): | ||
EvenIntegerValueObject(value=IntegerMother.invalid_type()) |
Oops, something went wrong.