Beispiel #1
0
    def validate(self, data):
        transaction_type = data['type']
        amount = data['amount']
        is_valid, message = TransactionService.validate_amount(
            transaction_type=transaction_type, amount=amount)
        if not is_valid:
            raise serializers.ValidationError({'amount': message})

        return data
Beispiel #2
0
    def test_validate_amount_when_inflow_is_positive_returns_true(self):
        inflow_transaction = Transaction.INFLOW
        amount = 10
        is_valid, message = TransactionService.validate_amount(
            transaction_type=inflow_transaction, amount=amount)

        expected_message = ''
        self.assertTrue(is_valid)
        self.assertEquals(expected_message, message)
Beispiel #3
0
    def test_validate_amount_when_outflow_is_positive_returns_false(self):
        outflow_transaction = Transaction.OUTFLOW
        amount = 10
        is_valid, message = TransactionService.validate_amount(
            transaction_type=outflow_transaction, amount=amount)

        expected_message = 'Amount must be negative'
        self.assertFalse(is_valid)
        self.assertEquals(expected_message, message)
Beispiel #4
0
    def test_validate_amount_when_outflow_is_negative_returns_true(self):
        outflow_transaction = Transaction.OUTFLOW
        amount = -10
        is_valid, message = TransactionService.validate_amount(
            transaction_type=outflow_transaction, amount=amount)

        expected_message = ''
        self.assertTrue(is_valid)
        self.assertEquals(expected_message, message)