예제 #1
0
    def test_should_is_valid_true_when_is_digit_is_called_with_non_digit_text(
            self):
        contract = Contract().requires().is_digit(value='Text',
                                                  field='year',
                                                  message='year invalid')

        self.assertFalse(contract.is_valid)
예제 #2
0
    def test_should_is_valid_false_when_is_false_is_called_with_value_true(
            self):
        contract = Contract().requires().is_false(value=True,
                                                  field='active',
                                                  message='active invalid')

        self.assertFalse(contract.is_valid)
예제 #3
0
    def test_should_is_valid_true_when_is_not_empty_is_called_with_value_is_not_empty(
            self):
        contract = Contract().requires().is_not_empty(value=uuid.uuid4(),
                                                      field='id',
                                                      message='id invalid')

        self.assertTrue(contract.is_valid)
예제 #4
0
    def test_should_is_valid_false_when_is_not_empty_is_called_with_value_is_empty(
            self):
        contract = Contract().requires().is_not_empty(value='',
                                                      field='id',
                                                      message='id invalid')

        self.assertFalse(contract.is_valid)
예제 #5
0
    def test_should_is_valid_false_when_is_none_is_called_with_value_not_none(
            self):
        contract = Contract().requires().is_none(value='anything',
                                                 field='name',
                                                 message='name invalid')

        self.assertFalse(contract.is_valid)
예제 #6
0
    def test_should_is_valid_false_when_is_url_is_called_with_invalid_url(
            self):
        contract = Contract().requires().is_url(value='invalid url',
                                                field='site',
                                                message='site invalid')

        self.assertFalse(contract.is_valid)
예제 #7
0
    def test_should_is_valid_true_when_is_email_is_called_with_a_valid_email(
            self):
        contract = Contract().requires().is_email(
            value='*****@*****.**',
            field='email',
            message='email invalid')

        self.assertTrue(contract.is_valid)
예제 #8
0
    def test_should_is_valid_false_when_has_len_is_called_with_value_different_than_len(
            self):
        contract = Contract().requires().has_len(value=None,
                                                 length=5,
                                                 field='name',
                                                 message='name invalid')

        self.assertFalse(contract.is_valid)
예제 #9
0
    def test_should_is_valid_true_when_has_len_is_called_with_value_has_same_than_length(
            self):
        contract = Contract().requires().has_len(value='Steve',
                                                 length=5,
                                                 field='name',
                                                 message='name invalid')

        self.assertTrue(contract.is_valid)
예제 #10
0
    def test_should_is_valid_false_when_has_max_len_is_called_with_value_has_more_maximum_len(
            self):
        contract = Contract().requires().has_max_len(value='Steve',
                                                     maximum=2,
                                                     field='name',
                                                     message='name invalid')

        self.assertFalse(contract.is_valid)
예제 #11
0
    def test_should_is_valid_false_when_has_min_len_is_called_with_value_is_none(
            self):
        contract = Contract().requires().has_min_len(value=None,
                                                     minimum=5,
                                                     field='name',
                                                     message='name invalid')

        self.assertFalse(contract.is_valid)
예제 #12
0
    def test_should_is_valid_true_when_has_min_len_is_called_with_value_contains_minimum_len(
            self):
        contract = Contract().requires().has_min_len(value='Steve',
                                                     minimum=5,
                                                     field='name',
                                                     message='name invalid')

        self.assertTrue(contract.is_valid)
예제 #13
0
    def test_should_is_valid_true_when_are_equals_is_called_with_value_is_equal_comparer(
            self):
        contract = Contract().requires().are_equals(value=100,
                                                    comparer=100,
                                                    field='wallet',
                                                    message='wallet invalid')

        self.assertTrue(contract.is_valid)
예제 #14
0
    def test_should_is_valid_false_when_is_email_or_empty_is_called_with_invalid_email(
            self):
        contract = Contract().requires().is_email_or_empty(
            value='parker_spiderman2001@gmail',
            field='email',
            message='email invalid')

        self.assertFalse(contract.is_valid)
예제 #15
0
    def test_should_is_valid_false_when_contains_is_called_with_value_not_in_text(
            self):
        contract = Contract().requires().contains(value='Stark',
                                                  text='Steve',
                                                  field='name',
                                                  message='name invalid')

        self.assertFalse(contract.is_valid)
예제 #16
0
    def test_should_is_valid_false_when_match_is_called_with_value_doesnt_match(
            self):
        contract = Contract().requires().match(value='Tony Stark',
                                               pattern=r".*(steve).*",
                                               field='name',
                                               message='invalid name')

        self.assertFalse(contract.is_valid)
예제 #17
0
    def test_should_is_valid_true_when_match_is_called_with_value_match_pattern(
            self):
        contract = Contract().requires().match(value='Tony Stark',
                                               pattern=r".*(stark).*",
                                               field='name',
                                               message='invalid name')

        self.assertTrue(contract.is_valid)
예제 #18
0
    def test_should_is_valid_true_when_is_url_or_empty_is_called_with_valid_url(
            self):
        contract = Contract().requires().is_url_or_empty(
            value='https://www.google.com',
            field='site',
            message='site invalid')

        self.assertTrue(contract.is_valid)
예제 #19
0
    def test_should_is_valid_false_when_has_min_length_if_not_none_or_empty_is_called_with_value_doesnt_contains_minimum_length(
            self):
        contract = Contract().requires().has_min_length_if_not_none_or_empty(
            value='Steve',
            field='contact',
            minimum=6,
            message='contact invalid')

        self.assertFalse(contract.is_valid)
예제 #20
0
    def test_should_is_valid_true_when_has_exact_length_if_not_none_or_empty_is_called_with_value_does_not_exact_length(
            self):
        contract = Contract().requires().has_exact_length_if_not_none_or_empty(
            value='Steve Rogers',
            length=5,
            field='contact',
            message='contact invalid')

        self.assertFalse(contract.is_valid)
예제 #21
0
    def test_should_is_valid_true_when_has_max_length_if_not_none_or_empty_is_called_with_value_exceed_maximum(
            self):
        contract = Contract().requires().has_max_length_if_not_none_or_empty(
            value='Steve',
            maximum=4,
            field='contact',
            message='contact invalid')

        self.assertFalse(contract.is_valid)
예제 #22
0
    def test_should_is_valid_false_when_is_greater_than_is_called_with_value_lower_than_comparer(
            self):
        contract = Contract().requires().is_greater_than(
            value=10,
            comparer=100,
            field='initial value',
            message='initial value invalid')

        self.assertFalse(contract.is_valid)
예제 #23
0
    def test_should_is_valid_true_when_is_greater_or_equals_than_is_called_with_value_greater_than_comparer(
            self):
        contract = Contract().requires().is_greater_or_equals_than(
            value=100.99,
            comparer=100.99,
            field='initial value',
            message='initial value invalid')

        self.assertTrue(contract.is_valid)
예제 #24
0
    def __init__(self, value):
        super().__init__()

        self._value = value

        self.add_notifications(Contract()
                               .requires()
                               .is_email(value=value,
                                         field='email',
                                         message='email not is valid'))
예제 #25
0
    def test_should_is_valid_true_when_is_between_is_called_with_value_in_range_of_to(
            self):
        begin_date = datetime(year=2019, month=1, day=1)
        end_date = datetime(year=2019, month=1, day=30)
        today = datetime(year=2019, month=1, day=15)

        contract = Contract().requires().is_between(value=today,
                                                    of=begin_date,
                                                    to=end_date,
                                                    field='birthday',
                                                    message='birthday invalid')

        self.assertTrue(contract.is_valid)
예제 #26
0
    def __init__(self, value, encrypt=True):
        super().__init__()

        self._value = self._encrypt(value) if encrypt else value

        self.add_notifications(Contract()
                               .requires()
                               .has_min_len(value=value,
                                            minimum=6,
                                            field='password',
                                            message='password should be min len 6')
                               .match(value=value,
                                      pattern=r'(?=.*[a-zA-Z]+).*',
                                      field='password',
                                      message='password should be alphabetic character')
                               .match(value=value,
                                      pattern=r'(?=.*\d+).*',
                                      field='password',
                                      message='password should be numeric character'))
예제 #27
0
    def __init__(self, title, description, value, work_date, receive_date=None, uid=None):
        super().__init__(uid=uid)

        self._title = title
        self._description = description
        self._value = value
        self._work_date = work_date
        self._receive_date = receive_date

        self.add_notifications(Contract()
                               .requires()
                               .is_not_none_or_empty(value=title,
                                                     field='title',
                                                     message='title should be informed')
                               .is_not_none_or_empty(value=description,
                                                     field='description',
                                                     message='description should be informed')
                               .is_greater_than(value=value,
                                                comparer=Decimal(0),
                                                field='value',
                                                message='value should be greater than zero')
                               .is_true(value=self._receive_date_is_valid(),
                                        field='receive_date',
                                        message='receive date should be greater than work date'))
예제 #28
0
    def test_should_is_valid_true_when_is_none_or_empty_is_called_with_value_none(
            self):
        contract = Contract().requires().is_none_or_empty(
            value=None, field='contact', message='contact invalid')

        self.assertTrue(contract.is_valid)
예제 #29
0
    def test_should_is_valid_false_when_is_none_or_empty_is_called_with_non_empty_value(
            self):
        contract = Contract().requires().is_none_or_empty(
            value='Anything', field='contact', message='contact invalid')

        self.assertFalse(contract.is_valid)
예제 #30
0
    def test_should_is_valid_true_when_has_exact_length_if_not_none_or_empty_is_called_with_value_empty(
            self):
        contract = Contract().requires().has_exact_length_if_not_none_or_empty(
            value='', length=10, field='contact', message='contact invalid')

        self.assertTrue(contract.is_valid)