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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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(order, 'pre-auth',
  13. D('10.00'), lines,
  14. line_quantities)
  15. # Has each line has been checked
  16. for line in lines:
  17. line.is_payment_event_permitted.assert_called_with('pre-auth',
  18. line.quantity)
  19. def test_invalid_lines(self):
  20. order = mock.Mock()
  21. invalid_line = mock.Mock()
  22. invalid_line.is_payment_event_permitted.return_value = False
  23. invalid_line.id = 6
  24. lines = [
  25. mock.Mock(),
  26. invalid_line,
  27. mock.Mock(),
  28. ]
  29. line_quantities = [line.quantity for line in lines]
  30. error = "The selected quantity for line #6 is too large"
  31. with self.assertRaisesRegex(exceptions.InvalidPaymentEvent, error):
  32. self.event_handler.validate_payment_event(order, 'payment',
  33. D('10.00'), lines,
  34. line_quantities)
  35. def test_no_lines(self):
  36. order = mock.Mock()
  37. lines = None
  38. line_quantities = None
  39. out = self.event_handler.validate_payment_event(
  40. order, 'payment', D('10.00'), lines, line_quantities)
  41. self.assertIsNone(out)