Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test view connect order with user
Anna Siwik4c710e0da07f
diff --git a/saleor/order/views.py b/saleor/order/views.pyindex be70f3c1d9..bb321de01c 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -153,7 +153,7 @@ def checkout_success(request, token):@login_requireddef connect_order_with_user(request, token):- """Connects newly created order to just logged in user."""+ """Connects newly created order to authenticated user."""try:order = Order.objects.get(user_email=request.user.email, token=token)except Order.DoesNotExist:diff --git a/tests/test_order.py b/tests/test_order.pyindex 5dde4c6968..0c8ffadea7 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -1,7 +1,9 @@+from django.urls import reversefrom prices import Pricefrom saleor.order import models, OrderStatusfrom saleor.order.utils import add_variant_to_delivery_group+from tests.utils import get_redirect_locationdef test_total_property():@@ -101,3 +103,30 @@ def test_order_queryset_closed_orders(open_orders, closed_orders):qs = models.Order.objects.closed()assert qs.count() == len(closed_orders)assert all([item in qs for item in closed_orders])+++def test_view_connect_order_with_user_authorized_user(+ order, authorized_client, customer_user):+ order.user_email = customer_user.email+ order.save()++ url = reverse(+ 'order:connect-order-with-user', kwargs={'token': order.token})+ response = authorized_client.post(url)++ redirect_location = get_redirect_location(response)+ assert redirect_location == reverse('order:details', args=[order.token])+ order.refresh_from_db()+ assert order.user == customer_user+++def test_view_connect_order_with_user_different_email(+ order, authorized_client):+ url = reverse(+ 'order:connect-order-with-user', kwargs={'token': order.token})+ response = authorized_client.post(url)++ redirect_location = get_redirect_location(response)+ assert redirect_location == reverse('profile:details')+ order.refresh_from_db()+ assert order.user is None