You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_processing.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from decimal import Decimal as D
  2. from unittest import mock
  3. from django.test import TestCase
  4. from oscar.apps.order import exceptions, processing
  5. class TestValidatePaymentEvent(TestCase):
  6. def setUp(self):
  7. self.event_handler = processing.EventHandler()
  8. def test_valid_lines(self):
  9. order = mock.Mock()
  10. lines = [mock.Mock() for r in range(3)]
  11. line_quantities = [line.quantity for line in lines]
  12. self.event_handler.validate_payment_event(
  13. order, "pre-auth", D("10.00"), lines, line_quantities
  14. )
  15. # Has each line has been checked
  16. for line in lines:
  17. line.is_payment_event_permitted.assert_called_with(
  18. "pre-auth", line.quantity
  19. )
  20. def test_invalid_lines(self):
  21. order = mock.Mock()
  22. invalid_line = mock.Mock()
  23. invalid_line.is_payment_event_permitted.return_value = False
  24. invalid_line.id = 6
  25. lines = [
  26. mock.Mock(),
  27. invalid_line,
  28. mock.Mock(),
  29. ]
  30. line_quantities = [line.quantity for line in lines]
  31. error = "The selected quantity for line #6 is too large"
  32. with self.assertRaisesRegex(exceptions.InvalidPaymentEvent, error):
  33. self.event_handler.validate_payment_event(
  34. order, "payment", D("10.00"), lines, line_quantities
  35. )
  36. def test_no_lines(self):
  37. order = mock.Mock()
  38. lines = None
  39. line_quantities = None
  40. # pylint: disable=assignment-from-no-return
  41. out = self.event_handler.validate_payment_event(
  42. order, "payment", D("10.00"), lines, line_quantities
  43. )
  44. self.assertIsNone(out)