Skip to content

Commit

Permalink
Refactor string validation contract #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Delatorre committed Mar 1, 2024
1 parent d221c63 commit 975b9de
Showing 1 changed file with 13 additions and 40 deletions.
53 changes: 13 additions & 40 deletions tests/validations/test_string_validation_contract.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from flunt.validations.contract import Contract

from flunt.validations.strings_validation_contract import StringValidationContract
from tests.mocks.entity.sample_entity import SampleEntity


def test_should_be_valid_when_is_lower_than_20(entity_mock: SampleEntity):
contract = Contract().is_lower_than(
contract = StringValidationContract().is_lower_than(
entity_mock.first_name, 20, 'first_name', 'any message'
)
assert contract.is_valid
Expand All @@ -13,7 +14,7 @@ def test_should_be_valid_when_is_lower_than_20(entity_mock: SampleEntity):
def test_should_be_invalid_and_return_once_notification_when_not_is_lower_than_5(
entity_mock: SampleEntity,
):
contract = Contract().is_lower_than(
contract = StringValidationContract().is_lower_than(
entity_mock.first_name, 5, 'first_name', 'any message'
)
assert contract.is_valid is False
Expand All @@ -23,7 +24,7 @@ def test_should_be_invalid_and_return_once_notification_when_not_is_lower_than_5
def test_should_be_valid_when_is_lower_or_equals_than_20(
entity_mock: SampleEntity,
):
contract = Contract().is_lower_or_equals_than(
contract = StringValidationContract().is_lower_or_equals_than(
entity_mock.first_name, 20, 'first_name', 'any message'
)
assert contract.is_valid
Expand All @@ -33,15 +34,15 @@ def test_should_be_valid_when_is_lower_or_equals_than_20(
def test_should_be_invalid_and_return_once_notification_when_not_is_lower_or_equals_than_14(
entity_mock: SampleEntity,
):
contract = Contract().is_lower_or_equals_than(
contract = StringValidationContract().is_lower_or_equals_than(
entity_mock.first_name, 14, 'first_name', 'any message'
)
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1


def test_should_be_valid_when_is_greater_than_10(entity_mock: SampleEntity):
contract = Contract().is_greater_than(
contract = StringValidationContract().is_greater_than(
entity_mock.first_name, 10, 'first_name', 'any message'
)
assert contract.is_valid
Expand All @@ -51,7 +52,7 @@ def test_should_be_valid_when_is_greater_than_10(entity_mock: SampleEntity):
def test_should_be_invalid_and_return_once_notification_when_not_is_greater_than_15(
entity_mock: SampleEntity,
):
contract = Contract().is_greater_than(
contract = StringValidationContract().is_greater_than(
entity_mock.first_name, 15, 'first_name', 'any message'
)
assert contract.is_valid is False
Expand All @@ -61,7 +62,7 @@ def test_should_be_invalid_and_return_once_notification_when_not_is_greater_than
def test_should_be_valid_when_is_greater_or_equals_than_13(
entity_mock: SampleEntity,
):
contract = Contract().is_greater_or_equals_than(
contract = StringValidationContract().is_greater_or_equals_than(
entity_mock.first_name, 13, 'first_name', 'any message'
)
assert contract.is_valid
Expand All @@ -71,59 +72,31 @@ def test_should_be_valid_when_is_greater_or_equals_than_13(
def test_should_be_invalid_and_return_once_notification_when_not_is_greater_or_equals_than_14(
entity_mock: SampleEntity,
):
contract = Contract().is_greater_or_equals_than(
contract = StringValidationContract().is_greater_or_equals_than(
entity_mock.first_name, 14, 'first_name', 'any message'
)
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1


def test_should_be_valid_when_is_none():
contract = Contract().is_none(None, 'first_name', 'any message') # type: ignore
assert contract.is_valid
assert len(contract.get_notifications()) == 0


def test_should_be_invalid_and_return_once_notification_when_not_is_none(
entity_mock: SampleEntity,
):
contract = Contract().is_none(entity_mock.first_name, 'first_name', 'any message')
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1


def test_should_be_valid_when_is_not_none(entity_mock: SampleEntity):
contract = Contract().is_not_none(
entity_mock.first_name, 'first_name', 'any message'
)
assert contract.is_valid
assert len(contract.get_notifications()) == 0


def test_should_be_invalid_and_return_once_notification_when_not_none():
contract = Contract().is_not_none(None, 'first_name', 'any message') # type: ignore
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1


def test_should_be_valid_when_is_not_none_or_white_space(
entity_mock: SampleEntity,
):
contract = Contract().is_not_none_or_white_space(
contract = StringValidationContract().is_not_none_or_white_space(
entity_mock.first_name, 'first_name', 'any message'
)
assert contract.is_valid
assert len(contract.get_notifications()) == 0


def test_should_be_invalid_and_return_once_notification_when_is_none():
contract = Contract().is_not_none_or_white_space(None, 'first_name', 'any message') # type: ignore
contract = StringValidationContract().is_not_none_or_white_space(None, 'first_name', 'any message') # type: ignore
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1


def test_should_be_invalid_and_return_once_notification_when_white_space():
contract = Contract().is_not_none_or_white_space(' ', 'first_name', 'any message')
contract = StringValidationContract().is_not_none_or_white_space(' ', 'first_name', 'any message')
assert contract.is_valid is False
assert len(contract.get_notifications()) == 1

Expand Down

0 comments on commit 975b9de

Please sign in to comment.