Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Apply changes after review
Maciej Korycinski63a31dd3c8ca
diff --git a/saleor/account/models.py b/saleor/account/models.pyindex 067e6fda96..a7d38c42f0 100644--- a/saleor/account/models.py+++ b/saleor/account/models.py@@ -165,7 +165,7 @@ class User(PermissionsMixin, ModelWithMetadata, AbstractBaseUser):)def __init__(self, *args, **kwargs):- super(User, self).__init__(*args, **kwargs)+ super().__init__(*args, **kwargs)self._effective_permissions = None@propertydiff --git a/saleor/plugins/webhook/__init__.py b/saleor/plugins/webhook/__init__.pyindex 2a1f6c97b7..2e9ecea710 100644--- a/saleor/plugins/webhook/__init__.py+++ b/saleor/plugins/webhook/__init__.py@@ -19,7 +19,11 @@ def create_webhook_headers():signature_prefix = "sha1="domain = Site.objects.get_current().domain- headers = {"X-Saleor-Event": event_name, "X-Saleor-Domain": domain}+ headers = {+ "Content-Type": "application/json",+ "X-Saleor-Event": event_name,+ "X-Saleor-Domain": domain,+ }if secret_key and body:saleor_hmac_sha256 = signature_prefix + create_hmac_signature(body, secret_key, encodingdiff --git a/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event.yaml b/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event.yamlindex 49906e4e59..d719bc601a 100644--- a/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event.yaml+++ b/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event.yaml@@ -1,14 +1,15 @@interactions:- request:- body: '[{"model": "order.order", "pk": 84, "fields": {"created": "2019-09-17T13:54:55.227Z",- "status": "unfulfilled", "user": 92, "language_code": "en", "tracking_client_id":- "", "billing_address": 351, "shipping_address": 352, "user_email": "[email protected]",- "currency": "USD", "shipping_method": 84, "shipping_method_name": "DHL", "shipping_price_net_amount":- "10.00", "shipping_price_gross_amount": "12.30", "token": "ce7b260c-f70d-430b-b88b-3519624a7974",+ body: '[{"model": "order.order", "pk": 18, "fields": {"private_metadata": {},+ "metadata": {}, "created": "2020-07-10T12:33:07.638Z", "status": "unfulfilled",+ "user": 19, "language_code": "en", "tracking_client_id": "", "billing_address":+ 75, "shipping_address": 76, "user_email": "[email protected]", "currency": "USD",+ "shipping_method": 20, "shipping_method_name": "DHL", "shipping_price_net_amount":+ "10.00", "shipping_price_gross_amount": "12.30", "token": "cabcc857-e7ba-4415-9bf8-56b1a8d805a5","checkout_token": "", "total_net_amount": "80.00", "total_gross_amount": "98.40",- "voucher": null, "discount_amount": "0.00", "discount_name": "", "translated_discount_name":- "", "display_gross_prices": true, "customer_note": "", "weight": "0.0 kg", "gift_cards":- []}}]'+ "voucher": null, "discount_amount": "0.00", "discount_name": null, "translated_discount_name":+ null, "display_gross_prices": true, "customer_note": "", "weight": "0.0:kg",+ "gift_cards": []}}]'headers:Accept:- '*/*'@@ -17,15 +18,17 @@ interactions:Connection:- keep-aliveContent-Length:- - '724'+ - '766'+ Content-Type:+ - application/jsonUser-Agent:- - python-requests/2.22.0+ - python-requests/2.24.0X-Saleor-Domain:- mirumee.comX-Saleor-Event:- order_createdmethod: POST- uri: https://webhook.site/f0fc9979-cbd4-47b7-8705-1acb03fff1d0+ uri: https://webhook.site/75048668-439a-4e54-853b-6f081a6fb6cfresponse:body:string: !!binary |@@ -38,21 +41,20 @@ interactions:Content-Type:- text/plain; charset=UTF-8Date:- - Tue, 17 Sep 2019 13:54:59 GMT+ - Fri, 10 Jul 2020 12:33:08 GMTServer:- - nginx/1.10.3+ - nginx/1.14.2+ Set-Cookie:+ - laravel_session=PVibhFdXrFzqlnOPwr4CMbPpCR9PqFxSBeisJ5Bp; expires=Fri, 10-Jul-2020+ 14:33:08 GMT; Max-Age=7200; path=/; httponlyTransfer-Encoding:- chunkedVary:- Accept-Encoding- X-RateLimit-Limit:- - '30'- X-RateLimit-Remaining:- - '29'X-Request-Id:- - 33161af9-c306-4918-ad9b-fad2b5b9897f+ - 61f48569-6ca6-43c6-a996-ad6a7e7984aaX-Token-Id:- - f0fc9979-cbd4-47b7-8705-1acb03fff1d0+ - 75048668-439a-4e54-853b-6f081a6fb6cfstatus:code: 200message: OKdiff --git a/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event_with_secret_key.yaml b/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event_with_secret_key.yamlindex 00740f3818..3a25c5675e 100644--- a/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event_with_secret_key.yaml+++ b/saleor/plugins/webhook/tests/cassettes/test_trigger_webhooks_for_event_with_secret_key.yaml@@ -1,14 +1,15 @@interactions:- request:- body: '[{"model": "order.order", "pk": 85, "fields": {"created": "2019-09-17T13:55:00.075Z",- "status": "unfulfilled", "user": 93, "language_code": "en", "tracking_client_id":- "", "billing_address": 355, "shipping_address": 356, "user_email": "[email protected]",- "currency": "USD", "shipping_method": 85, "shipping_method_name": "DHL", "shipping_price_net_amount":- "10.00", "shipping_price_gross_amount": "12.30", "token": "c71a5c72-7d0a-4505-ac1e-217b877fce24",+ body: '[{"model": "order.order", "pk": 26, "fields": {"private_metadata": {},+ "metadata": {}, "created": "2020-07-10T12:33:10.479Z", "status": "unfulfilled",+ "user": 27, "language_code": "en", "tracking_client_id": "", "billing_address":+ 107, "shipping_address": 108, "user_email": "[email protected]", "currency":+ "USD", "shipping_method": 28, "shipping_method_name": "DHL", "shipping_price_net_amount":+ "10.00", "shipping_price_gross_amount": "12.30", "token": "30a6f051-ae24-4bda-9cd0-732699fd7049","checkout_token": "", "total_net_amount": "80.00", "total_gross_amount": "98.40",- "voucher": null, "discount_amount": "0.00", "discount_name": "", "translated_discount_name":- "", "display_gross_prices": true, "customer_note": "", "weight": "0.0 kg", "gift_cards":- []}}]'+ "voucher": null, "discount_amount": "0.00", "discount_name": null, "translated_discount_name":+ null, "display_gross_prices": true, "customer_note": "", "weight": "0.0:kg",+ "gift_cards": []}}]'headers:Accept:- '*/*'@@ -17,17 +18,19 @@ interactions:Connection:- keep-aliveContent-Length:- - '724'+ - '768'+ Content-Type:+ - application/jsonUser-Agent:- - python-requests/2.22.0+ - python-requests/2.24.0X-Saleor-Domain:- mirumee.comX-Saleor-Event:- order_createdX-Saleor-HMAC-SHA256:- - sha1=43c77ab2a62add6e6a18dbf3346f87c55c4e50aefebc39f31160764686ed9048+ - sha1=aa3028c8e235adc0224b20ed92e6161aa917476452df5a8aef18af68533cae25method: POST- uri: https://webhook.site/f0fc9979-cbd4-47b7-8705-1acb03fff1d0+ uri: https://webhook.site/75048668-439a-4e54-853b-6f081a6fb6cfresponse:body:string: !!binary |@@ -40,21 +43,20 @@ interactions:Content-Type:- text/plain; charset=UTF-8Date:- - Tue, 17 Sep 2019 13:55:02 GMT+ - Fri, 10 Jul 2020 12:33:11 GMTServer:- - nginx/1.10.3+ - nginx/1.14.2+ Set-Cookie:+ - laravel_session=J2Z8HoMlOVIhLGE6eSAvcSrdC6l2zGtj0jRvkRwt; expires=Fri, 10-Jul-2020+ 14:33:11 GMT; Max-Age=7200; path=/; httponlyTransfer-Encoding:- chunkedVary:- Accept-Encoding- X-RateLimit-Limit:- - '30'- X-RateLimit-Remaining:- - '28'X-Request-Id:- - a731d727-0404-4bb9-b3d0-c0ba40491bce+ - 54babb5f-57c1-47d1-a004-e4d7f8edca46X-Token-Id:- - f0fc9979-cbd4-47b7-8705-1acb03fff1d0+ - 75048668-439a-4e54-853b-6f081a6fb6cfstatus:code: 200message: OKdiff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.pyindex 54bf96b5b9..faf72bf313 100644--- a/saleor/plugins/webhook/tests/test_webhook.py+++ b/saleor/plugins/webhook/tests/test_webhook.py@@ -29,7 +29,7 @@ def test_trigger_webhooks_for_event(permission_manage_products,):webhook.app.permissions.add(permission_manage_orders)- webhook.target_url = "https://webhook.site/f0fc9979-cbd4-47b7-8705-1acb03fff1d0"+ webhook.target_url = "https://webhook.site/75048668-439a-4e54-853b-6f081a6fb6cf"webhook.save()expected_data = serialize("json", [order_with_lines])@@ -37,6 +37,7 @@ def test_trigger_webhooks_for_event(trigger_webhooks_for_event(WebhookEventType.ORDER_CREATED, expected_data)expected_headers = {+ "Content-Type": "application/json","X-Saleor-Event": "order_created","X-Saleor-Domain": "mirumee.com",}@@ -112,7 +113,7 @@ def test_trigger_webhooks_for_event_with_secret_key(mock_request, webhook, order_with_lines, permission_manage_orders):webhook.app.permissions.add(permission_manage_orders)- webhook.target_url = "https://webhook.site/f0fc9979-cbd4-47b7-8705-1acb03fff1d0"+ webhook.target_url = "https://webhook.site/75048668-439a-4e54-853b-6f081a6fb6cf"webhook.secret_key = "secret_key"webhook.save()@@ -123,6 +124,7 @@ def test_trigger_webhooks_for_event_with_secret_key(expected_data, webhook.secret_key, "utf-8")expected_headers = {+ "Content-Type": "application/json","X-Saleor-Event": "order_created","X-Saleor-Domain": "mirumee.com","X-Saleor-HMAC-SHA256": f"sha1={expected_signature}",