Skip to content

Commit

Permalink
Fix flaky order payload serializer test (#9387)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszgrzyb committed Mar 22, 2022
1 parent efd8758 commit 76cf81e
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions saleor/webhook/tests/test_webhook_payloads.py
Expand Up @@ -54,6 +54,10 @@ def parse_django_datetime(date):
return json.loads(json.dumps(date, cls=DjangoJSONEncoder))


def sort_by_id(dicts):
return sorted(dicts, key=lambda d: d["id"])


@freeze_time()
@mock.patch("saleor.webhook.payloads.generate_order_lines_payload")
@mock.patch("saleor.webhook.payloads.generate_fulfillment_lines_payload")
Expand Down Expand Up @@ -196,28 +200,7 @@ def test_generate_order_payload(
"country_area": order.billing_address.country_area,
"phone": str(order.billing_address.phone),
},
"discounts": [
{
"id": graphene.Node.to_global_id("OrderDiscount", discount_1.pk),
"type": discount_1.type,
"value_type": discount_1.value_type,
"value": ANY,
"amount_value": str(quantize_price(discount_1.amount_value, currency)),
"name": discount_1.name,
"translated_name": discount_1.translated_name,
"reason": discount_1.reason,
},
{
"id": graphene.Node.to_global_id("OrderDiscount", discount_2.pk),
"type": discount_2.type,
"value_type": discount_2.value_type,
"value": ANY,
"amount_value": str(quantize_price(discount_2.amount_value, currency)),
"name": discount_2.name,
"translated_name": discount_2.translated_name,
"reason": discount_2.reason,
},
],
"discounts": ANY,
"original": graphene.Node.to_global_id("Order", order.original_id),
"lines": json.loads(order_lines),
"fulfillments": [
Expand Down Expand Up @@ -251,6 +234,31 @@ def test_generate_order_payload(
"meta": generate_meta(requestor_data=generate_requestor(customer_user)),
}

assert sort_by_id(payload["discounts"]) == sort_by_id(
[
{
"id": graphene.Node.to_global_id("OrderDiscount", discount_1.pk),
"type": discount_1.type,
"value_type": discount_1.value_type,
"value": ANY,
"amount_value": str(quantize_price(discount_1.amount_value, currency)),
"name": discount_1.name,
"translated_name": discount_1.translated_name,
"reason": discount_1.reason,
},
{
"id": graphene.Node.to_global_id("OrderDiscount", discount_2.pk),
"type": discount_2.type,
"value_type": discount_2.value_type,
"value": ANY,
"amount_value": str(quantize_price(discount_2.amount_value, currency)),
"name": discount_2.name,
"translated_name": discount_2.translated_name,
"reason": discount_2.reason,
},
],
)

mocked_fulfillment_lines.assert_called_with(fulfillment)


Expand Down

0 comments on commit 76cf81e

Please sign in to comment.