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