"""Refused payments become one plain sentence for the customer.""" import unittest from app import payment_messages as messages class PaymentMessageTests(unittest.TestCase): def test_a_refused_card_says_what_happened_and_what_to_do(self): self.assertIn('limite suficiente', messages.rejection('cc_rejected_insufficient_amount')) self.assertIn('código de segurança', messages.rejection('cc_rejected_bad_filled_security_code')) self.assertIn('Ligue para o banco', messages.rejection('cc_rejected_call_for_authorize')) # An unknown or missing code still reads as a sentence, never as the code. for detail in ('cc_rejected_something_new', None, ''): self.assertEqual(messages.rejection(detail), messages.REJECTED) self.assertNotIn('cc_', messages.rejection(detail)) def test_a_refused_request_names_the_field_to_fix(self): body = {'message': 'invalid parameters', 'cause': [{'code': 324, 'description': 'Invalid identification'}]} self.assertIn('CPF ou CNPJ', messages.refusal(body)) self.assertEqual(messages.refusal({'cause': [{'code': 10113}]}), messages.NOT_PROCESSED) self.assertEqual(messages.refusal({}), messages.NOT_PROCESSED) def test_quote_refusals_are_in_portuguese(self): self.assertIn('24 horas', messages.quote_refusal('quote expired before payment')) self.assertIn('cancelada', messages.quote_refusal('quote was discarded')) self.assertTrue(messages.quote_refusal('anything else').startswith('Não foi possível')) if __name__ == '__main__': unittest.main()