forked from saleor/saleor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_order_utils.py
57 lines (46 loc) · 1.69 KB
/
test_order_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pytest
from saleor.order.events import OrderEvents
from saleor.order.models import Order, OrderEvent
from saleor.order.utils import change_order_line_quantity, match_orders_with_new_user
@pytest.mark.parametrize(
"previous_quantity,new_quantity,added_count,removed_count",
((5, 2, 0, 3), (2, 5, 3, 0), (2, 0, 0, 2), (5, 5, 0, 0)),
)
def test_change_quantity_generates_proper_event(
previous_quantity,
new_quantity,
added_count,
removed_count,
order_with_lines,
staff_user,
):
assert not OrderEvent.objects.exists()
line = order_with_lines.lines.last()
line.quantity = previous_quantity
change_order_line_quantity(staff_user, line, previous_quantity, new_quantity)
if removed_count:
expected_type = OrderEvents.DRAFT_REMOVED_PRODUCTS
expected_quantity = removed_count
elif added_count:
expected_type = OrderEvents.DRAFT_ADDED_PRODUCTS
expected_quantity = added_count
else:
# No event should have occurred
assert not OrderEvent.objects.exists()
return
new_event = OrderEvent.objects.last() # type: OrderEvent
assert new_event.type == expected_type
assert new_event.user == staff_user
assert new_event.parameters == {
"lines": [
{"quantity": expected_quantity, "line_pk": line.pk, "item": str(line)}
]
}
def test_match_orders_with_new_user(customer_user):
address = customer_user.default_billing_address.get_copy()
order = Order.objects.create(
billing_address=address, user=None, user_email=customer_user.email,
)
match_orders_with_new_user(customer_user)
order.refresh_from_db()
assert order.user == customer_user