Ejemplo n.º 1
0
 def validate_customer_id(self, notification, bank_account):
     value = bank_account.customer_id
     if not value:
         raise Error('Customer id is required')
     try:
         value = int(value)
     except (ValueError, TypeError):
         raise Error('Customer id must be a integer number')
     self.customer_repository.get_customer_by_id(value)
     bank_account.customer_id = value
Ejemplo n.º 2
0
 def validate_number(self, notification, bank_account):
     value = bank_account.number
     if not value:
         raise Error('Account number is required')
     try:
         value = str(value)
     except (ValueError, TypeError):
         raise Error('Account number is not valid')
     if not re.match('([0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4})$', value):
         raise Error('Account number is not valid')
     if self.bank_account_repository.exists_account_number(bank_account.id, value):
         raise Error('Account number already exists')
     bank_account.number = value
Ejemplo n.º 3
0
 def validate_destination_account(self, notification, transaction):
     value = transaction.destination_account
     if not value:
         raise Error('Destination account is required')
     try:
         value = str(value)
     except (ValueError, TypeError):
         raise Error('Origen account is not valid')
     if not re.match('([0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{4})$', value):
         raise Error('Destination account number is not valid')
     try:
         transaction.destination_account = self.bank_account_repository.find_by_number(value)
     except Exception as ex:
         raise Error('Destination account: {}'.format(str(ex)))
Ejemplo n.º 4
0
 def validate_balance(self, notification, bank_account):
     value = bank_account.balance
     if not value:
         raise Error('Balance is required')
     try:
         value = float(value)
     except (ValueError, TypeError):
         notification.add_error('Balance number must be a decimal number')
     bank_account.balance = value
Ejemplo n.º 5
0
 def validate(self, bank_account):
     notification = Notification()
     self.validate_customer_id(notification, bank_account)
     self.validate_number(notification, bank_account)
     self.validate_balance(notification, bank_account)
     self.validate_is_locked(notification, bank_account)
     self.validate_type(notification, bank_account)
     if notification.has_errors():
         raise Error(notification.error_message())
     return bank_account
Ejemplo n.º 6
0
    def validate_bank_accounts(self, notification, origen_account,
                               destination_account):
        if not origen_account or not destination_account:
            raise Error(
                'Cannot perform the transfer. Invalid data in bank accounts specifications'
            )

        if origen_account.number == destination_account.number:
            notification.add_error(
                'Cannot transfer money to the same bank account')
Ejemplo n.º 7
0
 def validate_amount(self, notification, transaction):
     value = transaction.amount
     if not value:
         raise Error("Amount is required")
     try:
         value = Decimal(value)
     except (ValueError, TypeError):
         notification.add_error('Amount must be a decimal number')
     if value <= 0:
         notification.add_error('Amount must be greater than zero')
     transaction.amount = value
Ejemplo n.º 8
0
 def validate_amount(self, notification, amount):
     if not amount:
         raise Error('amount is missing')
     if amount <= 0:
         notification.add_error('The amount must be greater than zero')
Ejemplo n.º 9
0
 def validate(self, customer):
     notification = Notification()
     self.validate_document_number(notification, customer.id,
                                   customer.document_number)
     if notification.has_errors():
         raise Error(notification.error_message())