예제 #1
0
    def test_should_has_two_notifications_when_add_notifications_is_called_with_two_notifications(
            self):
        self._name.add_notifications(
            Notification(field='first name', message='first name invalid'),
            Notification(field='last name', message='last name invalid'),
        )

        self.assertEqual(2, len(self._name.notifications))
예제 #2
0
    def test_should_is_valid_false_when_add_notifications_is_called_with_two_notifications(
            self):
        self._name.add_notifications(
            Notification(field='first name', message='first name invalid'),
            Notification(field='last name', message='last name invalid'),
        )

        self.assertFalse(self._name.is_valid)
예제 #3
0
    def execute(self, command):
        user = self._user_repository.get_by_uid(command.user_uid)

        if not user:
            self.add_notification(Notification('user', 'user not exists'))
            return

        billing = self._user_repository.get_billing_by_uid(user, command.billing_uid)

        if not billing:
            self.add_notification(Notification('billing', 'billing not exists'))
            return

        self._user_repository.remove_billing(billing)
예제 #4
0
    def test_should_update_billing_return_errors_list_when_use_case_not_is_valid(
            self):
        is_valid = False
        billing_not_exists = Notification('billing', 'billing not exists')

        type(self._update_billing).is_valid = PropertyMock(
            return_value=is_valid)
        type(self._update_billing).notifications = PropertyMock(
            return_value=[billing_not_exists])

        billing_uid = str(uuid.uuid4())

        data = {
            'billing_uid': str(uuid.uuid4()),
            'title': 'Gas Station',
            'description': 'yesterday',
            'value': 10,
            'work_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        }

        _, response = self._client.put(f'/api/v1/billing/{billing_uid}',
                                       data=json.dumps(data))

        result = response.json['errors']

        expected = ['billing not exists']

        self.assertListEqual(expected, result)
예제 #5
0
    def is_url_or_empty(self, value, field, message):
        if not value or _valid_url(value):
            return self

        self.add_notification(Notification(field, message))

        return self
예제 #6
0
    def test_should_add_billing_return_errors_list_when_use_case_not_is_valid(
            self):
        is_valid = False
        wrong_password = Notification('title', 'title should be inform')

        type(self._add_billing).is_valid = PropertyMock(return_value=is_valid)
        type(self._add_billing).notifications = PropertyMock(
            return_value=[wrong_password])

        yesterday = datetime.now() + timedelta(days=1)

        data = {
            'title': 'Gas Station',
            'description': 'Yesterday',
            'value': 10,
            'work_date': yesterday.strftime('%Y-%m-%d %H:%M:%S')
        }

        _, response = self._client.post('/api/v1/billing',
                                        data=json.dumps(data))

        result = response.json['errors']

        expected = ['title should be inform']

        self.assertListEqual(expected, result)
예제 #7
0
    def execute(self, command):
        user = self._user_repository.get_by_uid(command.user_uid)

        if not user:
            self.add_notification(Notification('user', 'user not exists'))
            return

        billing = self._user_repository.get_billing_by_uid(user, command.billing_uid)

        if not billing:
            self.add_notification(Notification('billing', 'billing not exists'))

        if not self.is_valid:
            return

        user.cancel_receive_billing(billing)

        self._user_repository.save_billing(user, billing)
예제 #8
0
    def test_should_is_valid_false_when_add_notifications_is_called_with_a_invalid_notifiable(
            self):
        customer = Customer()

        self._name.add_notification(
            Notification(field='first name', message='first name invalid'))

        customer.add_notifications(self._name)

        self.assertFalse(customer.is_valid)
예제 #9
0
    def test_should_ensure_all_notifications_is_instance_of_notification_when_add_notifications(
            self):
        customer = Customer()

        self._name.add_notification(
            Notification(field='first name', message='first name invalid'))

        customer.add_notifications(self._name)

        self.assertTrue(
            all(isinstance(it, Notification) for it in customer.notifications))
예제 #10
0
    def execute(self, command):
        user = self._user_repository.get_by_uid(command.user_uid)

        if not user:
            self.add_notification(Notification('user', 'user not exists'))
            return

        billing = self._user_repository.get_billing_by_uid(user, command.billing_uid)

        if not billing:
            self.add_notification(Notification('Billing', 'billing not exists'))
            return

        billing = Billing(title=command.title,
                          description=command.description,
                          value=command.value,
                          work_date=command.work_date,
                          receive_date=billing.receive_date,
                          uid=billing.uid)

        self._user_repository.save_billing(user, billing)
예제 #11
0
    def test_should_return_status_code_bad_request_when_use_case_not_is_valid(self):
        is_valid = False
        wrong_password = Notification('password', 'wrong password')

        type(self._authenticate_user).is_valid = PropertyMock(return_value=is_valid)
        type(self._authenticate_user).notifications = PropertyMock(return_value=[wrong_password])

        data = {
            'email': '*****@*****.**',
            'password': '******'
        }

        _, response = self._client.post('/api/v1/account/authenticate', data=json.dumps(data))

        self.assertEqual(400, response.status_code)
예제 #12
0
    def test_should_remove_billing_return_status_code_bad_request_when_use_case_not_is_valid(
            self):
        is_valid = False
        billing_not_exists = Notification('billing', 'billing not exists')

        type(self._remove_billing).is_valid = PropertyMock(
            return_value=is_valid)
        type(self._remove_billing).notifications = PropertyMock(
            return_value=[billing_not_exists])

        billing_uid = str(uuid.uuid4())

        _, response = self._client.delete(f'/api/v1/billing/{billing_uid}')

        self.assertEqual(400, response.status_code)
예제 #13
0
    def test_should_return_errors_list_when_use_case_not_is_valid(self):
        is_valid = False
        email_not_is_valid = Notification('email', 'email not is valid')

        type(self._create_user).is_valid = PropertyMock(return_value=is_valid)
        type(self._create_user).notifications = PropertyMock(return_value=[email_not_is_valid])

        data = {
            'email': '*****@*****.**',
            'password': '******'
        }

        _, response = self._client.post('/api/v1/account', data=json.dumps(data))

        result = response.json['errors']

        expected = ['email not is valid']

        self.assertListEqual(expected, result)
예제 #14
0
    def test_should_remove_billing_return_errors_list_when_use_case_not_is_valid(
            self):
        is_valid = False
        billing_not_exists = Notification('billing', 'billing not exists')

        type(self._remove_billing).is_valid = PropertyMock(
            return_value=is_valid)
        type(self._remove_billing).notifications = PropertyMock(
            return_value=[billing_not_exists])

        billing_uid = str(uuid.uuid4())

        _, response = self._client.delete(f'/api/v1/billing/{billing_uid}')

        result = response.json['errors']

        expected = ['billing not exists']

        self.assertListEqual(expected, result)
예제 #15
0
    def test_should_return_errors_list_when_use_case_not_is_valid(self):
        is_valid = False
        wrong_password = Notification('password', 'wrong password')

        type(self._change_user_password).is_valid = PropertyMock(return_value=is_valid)
        type(self._change_user_password).notifications = PropertyMock(return_value=[wrong_password])

        data = {
            'email': '*****@*****.**',
            'old_password': '******',
            'new_password': '******'
        }

        _, response = self._client.post('/api/v1/account/change-password', data=json.dumps(data))

        result = response.json['errors']

        expected = ['wrong password']

        self.assertListEqual(expected, result)
예제 #16
0
    def execute(self, command):
        user = self._user_repository.get_by_uid(command.user_uid)

        if not user:
            self.add_notifications(Notification('user', 'user not exists'))
            return

        billing = Billing(title=command.title,
                          description=command.description,
                          value=command.value,
                          work_date=command.work_date)

        user.add_billing(billing)

        self.add_notifications(user, billing)

        if not self.is_valid:
            return

        for billing in user.billing:
            self._user_repository.save_billing(user, billing)
예제 #17
0
    def match(self, value, pattern, field, message):
        if not re.match(pattern, value, re.IGNORECASE):
            self.add_notification(Notification(field, message))

        return self
예제 #18
0
    def is_digit(self, value, field, message):
        if not value.isdigit():
            self.add_notification(Notification(field, message))

        return self
예제 #19
0
    def is_not_none_or_white_space(self, value, field, message):
        if not value or str(value).isspace():
            self.add_notification(Notification(field, message))

        return self
예제 #20
0
    def is_not_empty(self, value, field, message):
        if not value:
            self.add_notification(Notification(field, message))

        return self
예제 #21
0
    def is_url(self, value, field, message):
        if not _valid_url(value):
            self.add_notification(Notification(field, message))

        return self
예제 #22
0
    def has_max_length_if_not_none_or_empty(self, value, maximum, field,
                                            message):
        if value and len(value) > maximum:
            self.add_notification(Notification(field, message))

        return self
예제 #23
0
    def is_between(self, value, of, to, field, message):
        if not (of < value < to):
            self.add_notification(Notification(field, message))

        return self
예제 #24
0
    def is_lower_or_equals_than(self, value, comparer, field, message):
        if value > comparer:
            self.add_notification(Notification(field, message))

        return self
예제 #25
0
    def has_exact_length_if_not_none_or_empty(self, value, length, field,
                                              message):
        if value and len(value) != length:
            self.add_notification(Notification(field, message))

        return self
예제 #26
0
    def is_greater_than(self, value, comparer, field, message):
        if value <= comparer:
            self.add_notification(Notification(field, message))

        return self
예제 #27
0
    def is_none(self, value, field, message):
        if value is not None:
            self.add_notification(Notification(field, message))

        return self
예제 #28
0
    def are_not_equals(self, value, comparer, field, message):
        if value == comparer:
            self.add_notification(Notification(field, message))

        return self
예제 #29
0
    def is_false(self, value, field, message):
        if value:
            self.add_notification(Notification(field, message))

        return self
예제 #30
0
    def contains(self, value, text, field, message):
        if value not in text:
            self.add_notification(Notification(field, message))

        return self