Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Order checkout tests
Anna Siwikf54e11c33261
diff --git a/saleor/cart/checkout/utils.py b/saleor/cart/checkout/utils.pyindex 4492ea54b1..d618f373a5 100644--- a/saleor/cart/checkout/utils.py+++ b/saleor/cart/checkout/utils.py@@ -64,12 +64,12 @@ def update_shipping_address_in_cart(cart, user_addresses, data, country):if use_existing_address:address_id = addresses_form.cleaned_data['address']address = Address.objects.get(id=address_id)- save_shipping_address_in_cart(cart, address)+ change_shipping_address_in_cart(cart, address)updated = Trueelif address_form.is_valid():address = address_form.save()- save_shipping_address_in_cart(cart, address)+ change_shipping_address_in_cart(cart, address)updated = Truereturn addresses_form, address_form, updated@@ -90,7 +90,7 @@ def update_shipping_address_in_anonymous_cart(cart, data, country):if user_form.is_valid() and address_form.is_valid():user_form.save()address = address_form.save()- save_shipping_address_in_cart(cart, address)+ change_shipping_address_in_cart(cart, address)updated = Truereturn user_form, address_form, updated@@ -153,7 +153,7 @@ def update_billing_address_in_cart_with_shipping(address = address_form.save()if address:- save_billing_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)updated = Truereturn addresses_form, address_form, updated@@ -186,7 +186,7 @@ def update_billing_address_in_anonymous_cart(cart, data, country):if user_form.is_valid() and address_form.is_valid() and not preview:user_form.save()address = address_form.save()- save_billing_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)updated = Truereturn user_form, address_form, updated@@ -243,18 +243,18 @@ def update_billing_address_in_cart(cart, user_addresses, data, country):if use_existing_address:address_id = addresses_form.cleaned_data['address']address = Address.objects.get(id=address_id)- save_billing_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)updated = Trueelif address_form.is_valid():address = address_form.save()- save_billing_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)updated = Truereturn addresses_form, address_form, updated-def save_billing_address_in_cart(cart, address):+def change_billing_address_in_cart(cart, address):"""Save billing address in cart if changed.Remove previously saved address if not connected to any user.@@ -274,7 +274,7 @@ def save_billing_address_in_cart(cart, address):cart.save(update_fields=['billing_address'])-def save_shipping_address_in_cart(cart, address):+def change_shipping_address_in_cart(cart, address):"""Save shipping address in cart if changed.Remove previously saved address if not connected to any user.@@ -294,7 +294,7 @@ def save_shipping_address_in_cart(cart, address):cart.save(update_fields=['shipping_address'])-def get_checkout_data(cart, discounts, taxes):+def get_cart_data_for_checkout(cart, discounts, taxes):"""Data shared between views in checkout process."""lines = [(line, line.get_total(discounts, taxes)) for line in cart.lines.all()]diff --git a/saleor/cart/checkout/views/__init__.py b/saleor/cart/checkout/views/__init__.pyindex bc9962427c..09edc5c28f 100644--- a/saleor/cart/checkout/views/__init__.py+++ b/saleor/cart/checkout/views/__init__.py@@ -5,7 +5,7 @@ from ....account.forms import LoginFormfrom ....cart.models import Cartfrom ....cart.utils import get_or_empty_db_cartfrom ..forms import CartShippingMethodForm-from ..utils import get_checkout_data, get_taxes_for_cart+from ..utils import get_cart_data_for_checkout, get_taxes_for_cartfrom .discount import add_voucher_form, validate_voucherfrom .shipping import (anonymous_user_shipping_address_view, user_shipping_address_view)@@ -64,7 +64,7 @@ def shipping_method_view(request, cart):form.save()return redirect('cart:checkout-summary')- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'shipping_method_form': form})return TemplateResponse(request, 'checkout/shipping_method.html', ctx)diff --git a/saleor/cart/checkout/views/shipping.py b/saleor/cart/checkout/views/shipping.pyindex b4680a38bd..660119b26c 100644--- a/saleor/cart/checkout/views/shipping.py+++ b/saleor/cart/checkout/views/shipping.py@@ -2,7 +2,7 @@ from django.shortcuts import redirectfrom django.template.response import TemplateResponsefrom ..utils import (- get_checkout_data, get_taxes_for_cart,+ get_cart_data_for_checkout, get_taxes_for_cart,update_shipping_address_in_anonymous_cart, update_shipping_address_in_cart)@@ -16,7 +16,7 @@ def anonymous_user_shipping_address_view(request, cart):return redirect('cart:checkout-shipping-method')taxes = get_taxes_for_cart(cart, request.taxes)- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'address_form': address_form,'user_form': user_form})@@ -40,7 +40,7 @@ def user_shipping_address_view(request, cart):return redirect('cart:checkout-shipping-method')taxes = get_taxes_for_cart(cart, request.taxes)- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'additional_addresses': user_addresses,'address_form': address_form,diff --git a/saleor/cart/checkout/views/summary.py b/saleor/cart/checkout/views/summary.pyindex 1a00f375eb..13d4d3126d 100644--- a/saleor/cart/checkout/views/summary.py+++ b/saleor/cart/checkout/views/summary.py@@ -9,7 +9,7 @@ from ....core.exceptions import InsufficientStockfrom ....order.emails import send_order_confirmationfrom ..forms import CartNoteFormfrom ..utils import (- create_order, get_checkout_data, get_taxes_for_cart,+ create_order, get_cart_data_for_checkout, get_taxes_for_cart,update_billing_address_in_anonymous_cart, update_billing_address_in_cart,update_billing_address_in_cart_with_shipping)@@ -61,7 +61,7 @@ def summary_with_shipping_view(request, cart):return handle_order_placement(request, cart)taxes = get_taxes_for_cart(cart, request.taxes)- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'additional_addresses': user_addresses,'address_form': address_form,@@ -87,7 +87,7 @@ def anonymous_summary_without_shipping(request, cart):return handle_order_placement(request, cart)taxes = get_taxes_for_cart(cart, request.taxes)- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'address_form': address_form,'note_form': note_form,@@ -114,7 +114,7 @@ def summary_without_shipping(request, cart):return handle_order_placement(request, cart)taxes = get_taxes_for_cart(cart, request.taxes)- ctx = get_checkout_data(cart, request.discounts, taxes)+ ctx = get_cart_data_for_checkout(cart, request.discounts, taxes)ctx.update({'additional_addresses': user_addresses,'address_form': address_form,diff --git a/tests/test_cart.py b/tests/test_cart.pyindex aed0666ce1..33741bc2f8 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -633,3 +633,19 @@ def test_get_cart_data_no_shipping(request_cart_with_item, vatlayer):assert cart_total == TaxedMoney(net=Money('8.13', 'USD'), gross=Money(10, 'USD'))assert cart_data['total_with_shipping'].start == cart_total+++def test_cart_total_with_discount(request_cart_with_item, sale, vatlayer):+ total = (+ request_cart_with_item.get_total(discounts=(sale,), taxes=vatlayer))+ assert total == TaxedMoney(+ net=Money('4.07', 'USD'), gross=Money('5.00', 'USD'))+++def test_cart_taxes(request_cart_with_item, shipping_method, vatlayer):+ cart = request_cart_with_item+ cart.shipping_method = shipping_method.price_per_country.get()+ cart.save()+ taxed_price = TaxedMoney(net=Money('8.13', 'USD'), gross=Money(10, 'USD'))+ assert cart.get_shipping_price(taxes=vatlayer) == taxed_price+ assert cart.get_subtotal(taxes=vatlayer) == taxed_pricediff --git a/tests/test_checkout.py b/tests/test_checkout.pyindex ecb285fb75..c0724beb49 100644--- a/tests/test_checkout.py+++ b/tests/test_checkout.py@@ -1,5 +1,5 @@import datetime-from unittest.mock import Mock+from unittest.mock import Mock, patchimport pytestfrom django.urls import reverse@@ -11,10 +11,10 @@ from saleor.account.models import Addressfrom saleor.cart.checkout import viewsfrom saleor.cart.checkout.forms import CartVoucherFormfrom saleor.cart.checkout.utils import (- create_order, get_checkout_data, get_taxes_for_cart,+ change_billing_address_in_cart, change_shipping_address_in_cart,+ create_order, get_cart_data_for_checkout, get_taxes_for_cart,get_voucher_discount_for_cart, get_voucher_for_cart,- recalculate_cart_discount, remove_voucher_from_cart,- save_billing_address_in_cart, save_shipping_address_in_cart)+ recalculate_cart_discount, remove_voucher_from_cart)from saleor.cart.utils import add_variant_to_cartfrom saleor.core.exceptions import InsufficientStockfrom saleor.core.utils.taxes import (@@ -22,45 +22,342 @@ from saleor.core.utils.taxes import (from saleor.discount import DiscountValueType, VoucherTypefrom saleor.discount.models import NotApplicable, Voucher-from .utils import compare_taxes--[email protected]('cart, status_code, url', [- (Mock(__len__=Mock(return_value=0)), 302, reverse('cart:index')),- (- Mock(- __len__=Mock(return_value=1),- is_shipping_required=Mock(return_value=True)),- 302, reverse('cart:checkout-shipping-address')),- (- Mock(- __len__=Mock(return_value=1),- is_shipping_required=Mock(return_value=False)),- 302, reverse('cart:checkout-summary')),- (- Mock(- __len__=Mock(return_value=0),- is_shipping_required=Mock(return_value=False)),- 302, reverse('cart:index'))])-def test_index_view(cart, status_code, url, rf, monkeypatch):+from .utils import compare_taxes, get_redirect_location++[email protected]('cart_length, is_shipping_required, redirect_url', [+ (0, True, reverse('cart:index')),+ (0, False, reverse('cart:index')),+ (1, True, reverse('cart:checkout-shipping-address')),+ (1, False, reverse('cart:checkout-summary'))])+def test_view_checkout_index(+ monkeypatch, rf, cart_length, is_shipping_required, redirect_url):+ cart = Mock(+ __len__=Mock(return_value=cart_length),+ is_shipping_required=Mock(return_value=is_shipping_required))monkeypatch.setattr('saleor.cart.utils.get_cart_from_request', lambda req, qs: cart)- request = rf.get('cart:checkout-index', follow=True)+ url = reverse('cart:checkout-index')+ request = rf.get(url, follow=True)response = views.index_view(request)- assert response.status_code == status_code- assert response.url == url+ assert response.url == redirect_url+++def test_view_checkout_index_authorized_user(+ authorized_client, customer_user, request_cart_with_item):+ request_cart_with_item.user = customer_user+ request_cart_with_item.save()+ url = reverse('cart:checkout-index')++ response = authorized_client.get(url, follow=True)++ redirect_url = reverse('cart:checkout-shipping-address')+ assert response.request['PATH_INFO'] == redirect_url+++def test_view_checkout_shipping_address(client, request_cart_with_item):+ url = reverse('cart:checkout-shipping-address')+ data = {+ 'user_email': '[email protected]',+ 'first_name': 'John',+ 'last_name': 'Doe',+ 'street_address_1': 'Aleje Jerozolimskie 2',+ 'street_address_2': '',+ 'city': 'Warszawa',+ 'city_area': '',+ 'country_area': '',+ 'postal_code': '00-374',+ 'phone': '+48536984008',+ 'country': 'PL'}++ response = client.get(url)++ assert response.request['PATH_INFO'] == url++ response = client.post(url, data, follow=True)++ redirect_url = reverse('cart:checkout-shipping-method')+ assert response.request['PATH_INFO'] == redirect_url+ assert request_cart_with_item.user_email == '[email protected]'+++def test_view_checkout_shipping_address_authorized_user(+ authorized_client, customer_user, request_cart_with_item):+ request_cart_with_item.user = customer_user+ request_cart_with_item.save()+ url = reverse('cart:checkout-shipping-address')+ data = {'address': customer_user.default_billing_address.pk}++ response = authorized_client.post(url, data, follow=True)++ redirect_url = reverse('cart:checkout-shipping-method')+ assert response.request['PATH_INFO'] == redirect_url+ assert request_cart_with_item.user_email == customer_user.email+++def test_view_checkout_shipping_address_without_shipping(+ request_cart, product_without_shipping, client):+ variant = product_without_shipping.variants.get()+ add_variant_to_cart(request_cart, variant)+ url = reverse('cart:checkout-shipping-address')++ response = client.get(url)++ assert response.status_code == 302+ assert get_redirect_location(response) == reverse('cart:checkout-summary')+ assert not request_cart.user_email+++def test_view_checkout_shipping_method(+ client, shipping_method, address, request_cart_with_item):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.save()+ url = reverse('cart:checkout-shipping-method')+ data = {'shipping_method': shipping_method.price_per_country.first().pk}++ response = client.get(url)++ assert response.request['PATH_INFO'] == url++ response = client.post(url, data, follow=True)++ redirect_url = reverse('cart:checkout-summary')+ assert response.request['PATH_INFO'] == redirect_url+++def test_view_checkout_shipping_method_authorized_user(+ authorized_client, customer_user, shipping_method, address,+ request_cart_with_item):+ request_cart_with_item.user = customer_user+ request_cart_with_item.user_email = customer_user.email+ request_cart_with_item.shipping_address = address+ request_cart_with_item.save()+ url = reverse('cart:checkout-shipping-method')+ data = {'shipping_method': shipping_method.price_per_country.first().pk}++ response = authorized_client.get(url)++ assert response.request['PATH_INFO'] == url++ response = authorized_client.post(url, data, follow=True)++ redirect_url = reverse('cart:checkout-summary')+ assert response.request['PATH_INFO'] == redirect_url+++def test_view_checkout_shipping_method_without_shipping(+ request_cart, product_without_shipping, client):+ variant = product_without_shipping.variants.get()+ add_variant_to_cart(request_cart, variant)+ url = reverse('cart:checkout-shipping-method')++ response = client.get(url)++ assert response.status_code == 302+ assert get_redirect_location(response) == reverse('cart:checkout-summary')+++def test_view_checkout_shipping_method_without_address(+ request_cart_with_item, client):+ url = reverse('cart:checkout-shipping-method')++ response = client.get(url)++ assert response.status_code == 302+ redirect_url = reverse('cart:checkout-shipping-address')+ assert get_redirect_location(response) == redirect_url+++@patch('saleor.cart.checkout.views.summary.send_order_confirmation')+def test_view_checkout_summary(+ mock_send_confirmation, client, shipping_method, address,+ request_cart_with_item):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()+ url = reverse('cart:checkout-summary')+ data = {'address': 'shipping_address'}++ response = client.get(url)++ assert response.request['PATH_INFO'] == url++ response = client.post(url, data, follow=True)++ order = response.context['order']+ assert order.user_email == '[email protected]'+ redirect_url = reverse('order:payment', kwargs={'token': order.token})+ assert response.request['PATH_INFO'] == redirect_url+ mock_send_confirmation.delay.assert_called_once_with(order.pk)+++@patch('saleor.cart.checkout.views.summary.send_order_confirmation')+def test_view_checkout_summary_authorized_user(+ mock_send_confirmation, authorized_client, customer_user,+ shipping_method, address, request_cart_with_item):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user = customer_user+ request_cart_with_item.user_email = customer_user.email+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()+ url = reverse('cart:checkout-summary')+ data = {'address': 'shipping_address'}++ response = authorized_client.get(url)++ assert response.request['PATH_INFO'] == url++ response = authorized_client.post(url, data, follow=True)++ order = response.context['order']+ assert order.user_email == customer_user.email+ redirect_url = reverse('order:payment', kwargs={'token': order.token})+ assert response.request['PATH_INFO'] == redirect_url+ mock_send_confirmation.delay.assert_called_once_with(order.pk)-def test_checkout_discount(request_cart_with_item, sale, vatlayer):- total = (- request_cart_with_item.get_total(discounts=(sale,), taxes=vatlayer))- assert total == TaxedMoney(- net=Money('4.07', 'USD'), gross=Money('5.00', 'USD'))+@patch('saleor.cart.checkout.views.summary.send_order_confirmation')+def test_view_checkout_summary_save_language(+ mock_send_confirmation, authorized_client, customer_user,+ shipping_method, address, request_cart_with_item, settings):+ settings.LANGUAGE_CODE = 'en'+ user_language = 'fr'+ authorized_client.cookies[settings.LANGUAGE_COOKIE_NAME] = user_language+ url = reverse('set_language')+ data = {'language': 'fr'}+ authorized_client.post(url, data)-def test_checkout_create_order_insufficient_stock(+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user = customer_user+ request_cart_with_item.user_email = customer_user.email+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()+ url = reverse('cart:checkout-summary')+ data = {'address': 'shipping_address'}++ response = authorized_client.get(url, HTTP_ACCEPT_LANGUAGE=user_language)++ assert response.request['PATH_INFO'] == url++ response = authorized_client.post(+ url, data, follow=True, HTTP_ACCEPT_LANGUAGE=user_language)++ order = response.context['order']+ assert order.user_email == customer_user.email+ assert order.language_code == user_language+ redirect_url = reverse('order:payment', kwargs={'token': order.token})+ assert response.request['PATH_INFO'] == redirect_url+ mock_send_confirmation.delay.assert_called_once_with(order.pk)+++def test_view_checkout_summary_without_address(request_cart_with_item, client):+ url = reverse('cart:checkout-summary')++ response = client.get(url)++ assert response.status_code == 302+ redirect_url = reverse('cart:checkout-shipping-method')+ assert get_redirect_location(response) == redirect_url+++def test_view_checkout_summary_without_shipping_method(+ request_cart_with_item, client):+ url = reverse('cart:checkout-summary')++ response = client.get(url)++ assert response.status_code == 302+ redirect_url = reverse('cart:checkout-shipping-method')+ assert get_redirect_location(response) == redirect_url+++def test_view_checkout_summary_with_invalid_voucher(+ client, request_cart_with_item, shipping_method, address, voucher):+ voucher.usage_limit = 3+ voucher.save()++ request_cart_with_item.shipping_address = address+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()++ url = reverse('cart:checkout-summary')+ voucher_url = '{url}?next={url}'.format(url=url)+ data = {'discount-voucher': voucher.code}++ response = client.post(voucher_url, data, follow=True, HTTP_REFERER=url)++ assert response.context['cart'].voucher_code == voucher.code++ voucher.used = 3+ voucher.save()++ data = {'address': 'shipping_address'}+ response = client.post(url, data, follow=True)+ cart = response.context['cart']+ assert not cart.voucher_code+ assert not cart.discount_amount+ assert not cart.discount_name++ response = client.post(url, data, follow=True)+ order = response.context['order']+ assert not order.voucher+ assert not order.discount_amount+ assert not order.discount_name+++def test_view_checkout_summary_with_invalid_voucher_code(+ client, request_cart_with_item, shipping_method, address):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()++ url = reverse('cart:checkout-summary')+ voucher_url = '{url}?next={url}'.format(url=url)+ data = {'discount-voucher': 'invalid-code'}++ response = client.post(voucher_url, data, follow=True, HTTP_REFERER=url)++ assert 'voucher' in response.context['voucher_form'].errors+ assert response.context['cart'].voucher_code is None+++def test_view_checkout_summary_remove_voucher(+ client, request_cart_with_item, shipping_method, voucher, address):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()++ remove_voucher_url = reverse('cart:checkout-summary')+ voucher_url = '{url}?next={url}'.format(url=remove_voucher_url)+ data = {'discount-voucher': voucher.code}++ response = client.post(+ voucher_url, data, follow=True, HTTP_REFERER=remove_voucher_url)++ assert response.context['cart'].voucher_code == voucher.code++ url = reverse('cart:checkout-remove-voucher')++ response = client.post(url, follow=True, HTTP_REFERER=remove_voucher_url)++ assert not response.context['cart'].voucher_code+++def test_create_order_insufficient_stock(request_cart, customer_user, product_without_shipping):variant = product_without_shipping.variants.get()add_variant_to_cart(request_cart, variant, 10, check_quantity=False)@@ -73,50 +370,47 @@ def test_checkout_create_order_insufficient_stock(request_cart, 'tracking_code', discounts=None, taxes=None)-def test_checkout_taxes(request_cart_with_item, shipping_method, vatlayer):- cart = request_cart_with_item- cart.shipping_method = shipping_method.price_per_country.get()- cart.save()- taxed_price = TaxedMoney(net=Money('8.13', 'USD'), gross=Money(10, 'USD'))- assert cart.get_shipping_price(taxes=vatlayer) == taxed_price- assert cart.get_subtotal(taxes=vatlayer) == taxed_price--def test_note_in_created_order(request_cart_with_item, address):request_cart_with_item.shipping_address = address- request_cart_with_item.note = ''+ request_cart_with_item.note = 'test_note'request_cart_with_item.save()order = create_order(request_cart_with_item, 'tracking_code', discounts=None, taxes=None)- assert not order.notes.all()+ assert order.notes.filter(content='test_note').exists()- request_cart_with_item.note = 'test_note'++def test_note_in_created_order_empty_note(request_cart_with_item, address):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.note = ''request_cart_with_item.save()order = create_order(request_cart_with_item, 'tracking_code', discounts=None, taxes=None)- assert order.notes.filter(content='test_note').exists()+ assert not order.notes.all()@pytest.mark.parametrize(- 'total, discount_value, discount_type, limit, expected_value', [+ 'total, discount_value, discount_type, limit, discount_amount', [('100', 10, DiscountValueType.FIXED, None, 10),('100.05', 10, DiscountValueType.PERCENTAGE, 100, 10)])-def test_value_voucher_checkout_discount(- settings, total, discount_value, discount_type, limit, expected_value):+def test_get_discount_for_cart_value_voucher(+ settings, total, discount_value, discount_type, limit,+ discount_amount):voucher = Voucher(- code='unique', type=VoucherType.VALUE,+ code='unique',+ type=VoucherType.VALUE,discount_value_type=discount_type,discount_value=discount_value,limit=Money(limit, 'USD') if limit is not None else None)subtotal = TaxedMoney(net=Money(total, 'USD'), gross=Money(total, 'USD'))cart = Mock(get_subtotal=Mock(return_value=subtotal))discount = get_voucher_discount_for_cart(voucher, cart)- assert discount == Money(expected_value, 'USD')+ assert discount == Money(discount_amount, 'USD')-def test_value_voucher_checkout_discount_not_applicable(settings):+def test_get_discount_for_cart_value_voucher_not_applicable(settings):voucher = Voucher(- code='unique', type=VoucherType.VALUE,+ code='unique',+ type=VoucherType.VALUE,discount_value_type=DiscountValueType.FIXED,discount_value=10,limit=Money(100, 'USD'))@@ -128,12 +422,13 @@ def test_value_voucher_checkout_discount_not_applicable(settings):@pytest.mark.parametrize(- 'shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value', [ # noqa+ 'shipping_cost, shipping_country_code, discount_value, discount_type,'+ 'apply_to, expected_value', [(10, None, 50, DiscountValueType.PERCENTAGE, None, 5),(10, None, 20, DiscountValueType.FIXED, None, 10),(10, 'PL', 20, DiscountValueType.FIXED, '', 10),(5, 'PL', 5, DiscountValueType.FIXED, 'PL', 5)])-def test_shipping_voucher_checkout_discount(+def test_get_discount_for_cart_shipping_voucher(settings, shipping_cost, shipping_country_code, discount_value,discount_type, apply_to, expected_value):subtotal = TaxedMoney(net=Money(100, 'USD'), gross=Money(100, 'USD'))@@ -157,7 +452,7 @@ def test_shipping_voucher_checkout_discount(@pytest.mark.parametrize(- 'is_shipping_required, shipping_method, discount_value, discount_type, '+ 'is_shipping_required, shipping_method, discount_value, discount_type,''apply_to, limit, subtotal, error_msg', [(True, Mock(country_code='PL'), 10, DiscountValueType.FIXED,'US', None, Money(10, 'USD'),@@ -171,7 +466,7 @@ def test_shipping_voucher_checkout_discount((True, Mock(price=Money(10, 'USD')), 10,DiscountValueType.FIXED, None, 5, Money(2, 'USD'),'This offer is only valid for orders over $5.00.')])-def test_shipping_voucher_checkout_discount_not_applicable(+def test_get_discount_for_cart_shipping_voucher_not_applicable(settings, is_shipping_required, shipping_method, discount_value,discount_type, apply_to, limit, subtotal, error_msg):subtotal_price = TaxedMoney(net=subtotal, gross=subtotal)@@ -190,7 +485,7 @@ def test_shipping_voucher_checkout_discount_not_applicable(assert str(e.value) == error_msg-def test_product_voucher_checkout_discount_not_applicable(+def test_get_discount_for_cart_product_voucher_not_applicable(settings, monkeypatch):monkeypatch.setattr('saleor.cart.checkout.utils.get_product_variants_and_prices',@@ -199,14 +494,14 @@ def test_product_voucher_checkout_discount_not_applicable(code='unique', type=VoucherType.PRODUCT,discount_value_type=DiscountValueType.FIXED,discount_value=10)- cart=Mock()+ cart = Mock()with pytest.raises(NotApplicable) as e:get_voucher_discount_for_cart(voucher, cart)assert str(e.value) == 'This offer is only valid for selected items.'-def test_category_voucher_checkout_discount_not_applicable(+def test_get_discount_for_cart_category_voucher_not_applicable(settings, monkeypatch):monkeypatch.setattr('saleor.cart.checkout.utils.get_category_variants_and_prices',@@ -216,12 +511,13 @@ def test_category_voucher_checkout_discount_not_applicable(discount_value_type=DiscountValueType.FIXED,discount_value=10)cart = Mock()+with pytest.raises(NotApplicable) as e:get_voucher_discount_for_cart(voucher, cart)assert str(e.value) == 'This offer is only valid for selected items.'-def test_checkout_discount_form_invalid_voucher_code(+def test_cart_voucher_form_invalid_voucher_code(monkeypatch, request_cart_with_item):form = CartVoucherForm({'voucher': 'invalid'}, instance=request_cart_with_item)@@ -229,7 +525,7 @@ def test_checkout_discount_form_invalid_voucher_code(assert 'voucher' in form.errors-def test_checkout_discount_form_not_applicable_voucher(+def test_cart_voucher_form_voucher_not_applicable(voucher, request_cart_with_item):voucher.limit = 200voucher.save()@@ -239,7 +535,7 @@ def test_checkout_discount_form_not_applicable_voucher(assert 'voucher' in form.errors-def test_checkout_discount_form_active_queryset_voucher_not_active(+def test_cart_voucher_form_active_queryset_voucher_not_active(voucher, request_cart_with_item):assert Voucher.objects.count() == 1voucher.start_date = datetime.date.today() + datetime.timedelta(days=1)@@ -250,7 +546,7 @@ def test_checkout_discount_form_active_queryset_voucher_not_active(assert qs.count() == 0-def test_checkout_discount_form_active_queryset_voucher_active(+def test_cart_voucher_form_active_queryset_voucher_active(voucher, request_cart_with_item):assert Voucher.objects.count() == 1voucher.start_date = datetime.date.today()@@ -261,7 +557,7 @@ def test_checkout_discount_form_active_queryset_voucher_active(assert qs.count() == 1-def test_checkout_discount_form_active_queryset_after_some_time(+def test_cart_voucher_form_active_queryset_after_some_time(voucher, request_cart_with_item):assert Voucher.objects.count() == 1voucher.start_date = datetime.date(year=2016, month=6, day=1)@@ -360,8 +656,9 @@ def test_recalculate_cart_discount_expired_voucher(cart_with_voucher, voucher):assert cart.discount_amount == ZERO_MONEY-def test_get_checkout_data(cart_with_voucher, vatlayer):- line_price = TaxedMoney(net=Money('24.39', 'USD'), gross=Money('30.00', 'USD'))+def test_get_cart_data_for_checkout(cart_with_voucher, vatlayer):+ line_price = TaxedMoney(+ net=Money('24.39', 'USD'), gross=Money('30.00', 'USD'))expected_data = {'cart': cart_with_voucher,'cart_are_taxes_handled': True,@@ -370,57 +667,58 @@ def test_get_checkout_data(cart_with_voucher, vatlayer):'cart_subtotal': line_price,'cart_total': line_price - cart_with_voucher.discount_amount}- data = get_checkout_data(cart_with_voucher, discounts=None, taxes=vatlayer)+ data = get_cart_data_for_checkout(+ cart_with_voucher, discounts=None, taxes=vatlayer)assert data == expected_data-def test_save_address_in_cart(cart, address):- save_shipping_address_in_cart(cart, address)- save_billing_address_in_cart(cart, address)+def test_change_address_in_cart(cart, address):+ change_shipping_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)cart.refresh_from_db()assert cart.shipping_address == addressassert cart.billing_address == address-def test_save_address_in_cart_to_none(cart, address):+def test_change_address_in_cart_to_none(cart, address):cart.shipping_address = addresscart.billing_address = address.get_copy()cart.save()- save_shipping_address_in_cart(cart, None)- save_billing_address_in_cart(cart, None)+ change_shipping_address_in_cart(cart, None)+ change_billing_address_in_cart(cart, None)cart.refresh_from_db()assert cart.shipping_address is Noneassert cart.billing_address is None-def test_save_address_in_cart_to_same(cart, address):+def test_change_address_in_cart_to_same(cart, address):cart.shipping_address = addresscart.billing_address = address.get_copy()cart.save(update_fields=['shipping_address', 'billing_address'])shipping_address_id = cart.shipping_address.idbilling_address_id = cart.billing_address.id- save_shipping_address_in_cart(cart, address)- save_billing_address_in_cart(cart, address)+ change_shipping_address_in_cart(cart, address)+ change_billing_address_in_cart(cart, address)cart.refresh_from_db()assert cart.shipping_address.id == shipping_address_idassert cart.billing_address.id == billing_address_id-def test_save_address_in_cart_to_other(cart, address):+def test_change_address_in_cart_to_other(cart, address):address_id = address.idcart.shipping_address = addresscart.billing_address = address.get_copy()cart.save(update_fields=['shipping_address', 'billing_address'])other_address = Address.objects.create(country=Country('DE'))- save_shipping_address_in_cart(cart, other_address)- save_billing_address_in_cart(cart, other_address)+ change_shipping_address_in_cart(cart, other_address)+ change_billing_address_in_cart(cart, other_address)cart.refresh_from_db()assert cart.shipping_address == other_address@@ -428,7 +726,8 @@ def test_save_address_in_cart_to_other(cart, address):assert not Address.objects.filter(id=address_id).exists()-def test_save_address_in_cart_to_other_with_user(cart, customer_user, address):+def test_change_address_in_cart_from_user_address_to_other(+ cart, customer_user, address):address_id = address.idcart.user = customer_usercart.shipping_address = address@@ -436,8 +735,8 @@ def test_save_address_in_cart_to_other_with_user(cart, customer_user, address):cart.save(update_fields=['shipping_address', 'billing_address'])other_address = Address.objects.create(country=Country('DE'))- save_shipping_address_in_cart(cart, other_address)- save_billing_address_in_cart(cart, other_address)+ change_shipping_address_in_cart(cart, other_address)+ change_billing_address_in_cart(cart, other_address)cart.refresh_from_db()assert cart.shipping_address == other_addressdiff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.pydeleted file mode 100644index 7d70377e94..0000000000--- a/tests/test_checkout_integration.py+++ /dev/null@@ -1,514 +0,0 @@-from unittest.mock import patch--from django.urls import reverse-from payments import FraudStatus, PaymentStatus--from saleor.account.models import User-from saleor.cart.checkout.utils import create_order-from saleor.cart.utils import add_variant_to_cart--from .utils import get_redirect_location---def test_checkout_index(client, request_cart_with_item):- url = reverse('cart:checkout-index')-- response = client.get(url, follow=True)-- redirect_url = reverse('cart:checkout-shipping-address')- assert response.request['PATH_INFO'] == redirect_url---def test_checkout_index_authorized_user(- authorized_client, customer_user, request_cart_with_item):- request_cart_with_item.user = customer_user- request_cart_with_item.save()- url = reverse('cart:checkout-index')-- response = authorized_client.get(url, follow=True)-- redirect_url = reverse('cart:checkout-shipping-address')- assert response.request['PATH_INFO'] == redirect_url---def test_checkout_shipping_address(client, request_cart_with_item):- url = reverse('cart:checkout-shipping-address')- data = {- 'user_email': '[email protected]',- 'first_name': 'John',- 'last_name': 'Doe',- 'street_address_1': 'Aleje Jerozolimskie 2',- 'street_address_2': '',- 'city': 'Warszawa',- 'city_area': '',- 'country_area': '',- 'postal_code': '00-374',- 'phone': '+48536984008',- 'country': 'PL'}-- response = client.get(url)-- assert response.request['PATH_INFO'] == url-- response = client.post(url, data=data, follow=True)-- redirect_url = reverse('cart:checkout-shipping-method')- assert response.request['PATH_INFO'] == redirect_url---def test_checkout_shipping_address_authorized_user(- authorized_client, customer_user, request_cart_with_item):- request_cart_with_item.user = customer_user- request_cart_with_item.save()- url = reverse('cart:checkout-shipping-address')- data = {'address': customer_user.default_billing_address.pk}-- response = authorized_client.post(url, data=data, follow=True)-- redirect_url = reverse('cart:checkout-shipping-method')- assert response.request['PATH_INFO'] == redirect_url---def test_checkout_shipping_method(- client, shipping_method, address, request_cart_with_item):- request_cart_with_item.shipping_address = address- request_cart_with_item.user_email = '[email protected]'- request_cart_with_item.save()- url = reverse('cart:checkout-shipping-method')- data = {'shipping_method': shipping_method.price_per_country.first().pk}-- response = client.get(url)-- assert response.request['PATH_INFO'] == url-- response = client.post(url, data=data, follow=True)-- redirect_url = reverse('cart:checkout-summary')- assert response.request['PATH_INFO'] == redirect_url---def test_checkout_shipping_method_authorized_user(- authorized_client, customer_user, shipping_method, address,- request_cart_with_item):- request_cart_with_item.user = customer_user- request_cart_with_item.user_email = customer_user.email- request_cart_with_item.shipping_address = address- request_cart_with_item.save()- url = reverse('cart:checkout-shipping-method')- data = {'shipping_method': shipping_method.price_per_country.first().pk}-- response = authorized_client.get(url)-- assert response.request['PATH_INFO'] == url-- response = authorized_client.post(url, data=data, follow=True)-- redirect_url = reverse('cart:checkout-summary')- assert response.request['PATH_INFO'] == redirect_url---@patch('saleor.cart.checkout.views.summary.send_order_confirmation')-def test_checkout_summary(- mock_send_confirmation, client, shipping_method, address,- request_cart_with_item):- request_cart_with_item.shipping_address = address- request_cart_with_item.user_email = '[email protected]'- request_cart_with_item.shipping_method = (- shipping_method.price_per_country.first())- request_cart_with_item.save()- url = reverse('cart:checkout-summary')- data = {'address': 'shipping_address'}-- response = client.get(url)-- assert response.request['PATH_INFO'] == url-- response = client.post(url, data=data, follow=True)-- order = response.context['order']- redirect_url = reverse('order:payment', kwargs={'token': order.token})- assert response.request['PATH_INFO'] == redirect_url- mock_send_confirmation.delay.assert_called_once_with(order.pk)---@patch('saleor.cart.checkout.views.summary.send_order_confirmation')-def test_checkout_summary_authorized_user(- mock_send_confirmation, authorized_client, customer_user,- shipping_method, address, request_cart_with_item):- request_cart_with_item.shipping_address = address- request_cart_with_item.user = customer_user- request_cart_with_item.user_email = customer_user.email- request_cart_with_item.shipping_method = (- shipping_method.price_per_country.first())- request_cart_with_item.save()- url = reverse('cart:checkout-summary')- data = {'address': 'shipping_address'}-- response = authorized_client.get(url)-- assert response.request['PATH_INFO'] == url-- response = authorized_client.post(url, data=data, follow=True)-- order = response.context['order']- redirect_url = reverse('order:payment', kwargs={'token': order.token})- assert response.request['PATH_INFO'] == redirect_url- mock_send_confirmation.delay.assert_called_once_with(order.pk)---def test_new_order_payment(- request_cart_with_item, client, address, shipping_method):- request_cart_with_item.shipping_address = address- request_cart_with_item.billing_address = address.get_copy()- request_cart_with_item.user_email = '[email protected]'- request_cart_with_item.shipping_method = (- shipping_method.price_per_country.first())- request_cart_with_item.save()-- order = create_order(- request_cart_with_item, 'tracking_code', discounts=None, taxes=None)-- # Select payment method- url = reverse('order:payment', kwargs={'token': order.token})- payment_page = client.post(url, data={'method': 'default'}, follow=True)- assert len(payment_page.redirect_chain) == 1- assert payment_page.status_code == 200- # Go to payment details page, enter payment data- payment_page_url = payment_page.redirect_chain[0][0]- payment_data = {- 'status': PaymentStatus.PREAUTH,- 'fraud_status': FraudStatus.UNKNOWN,- 'gateway_response': '3ds-disabled',- 'verification_result': 'waiting'}- payment_response = client.post(payment_page_url, data=payment_data)- assert payment_response.status_code == 302- payment_redirect = reverse(- 'order:payment-success', kwargs={'token': order.token})- assert get_redirect_location(payment_response) == payment_redirect- success_response = client.post(payment_redirect, data={'status': 'ok'})- assert success_response.status_code == 302- order_password = reverse(- 'order:checkout-success', kwargs={'token': order.token})- assert get_redirect_location(success_response) == order_password---def test_new_order_payment_authorized_user(- authorized_client, request_cart_with_item, customer_user,- shipping_method):- request_cart_with_item.user = customer_user- request_cart_with_item.shipping_address = (- customer_user.default_shipping_address)- request_cart_with_item.billing_address = (- customer_user.default_billing_address)- request_cart_with_item.shipping_method = (- shipping_method.price_per_country.first())- request_cart_with_item.save()-- order = create_order(- request_cart_with_item, 'tracking_code', discounts=None, taxes=None)-- # Select payment method- url = reverse('order:payment', kwargs={'token': order.token})- payment_page = authorized_client.post(- url, data={'method': 'default'}, follow=True)-- # Go to payment details page, enter payment data- payment_data = {- 'status': PaymentStatus.PREAUTH,- 'fraud_status': FraudStatus.UNKNOWN,- 'gateway_response': '3ds-disabled',- 'verification_result': 'waiting'}- payment_response = authorized_client.post(- payment_page.request['PATH_INFO'], data=payment_data)-- assert payment_response.status_code == 302- order_password = reverse(- 'order:payment-success', kwargs={'token': order.token})- assert get_redirect_location(payment_response) == order_password-- # Assert that payment object was created and contains correct data- payment = order.payments.all()[0]- assert payment.total == order.total.gross.amount- assert payment.tax == order.total.tax.amount- assert payment.currency == order.total.currency- assert payment.delivery == order.shipping_price.net.amount- assert len(payment.get_purchased_items()) == len(order.lines.all())---def test_address_without_shipping(- request_cart, product_without_shipping, client):- variant = product_without_shipping.variants.get()- add_variant_to_cart(request_cart, variant)-- response = client.get(reverse('cart:checkout-shipping-address'))- assert response.status_code == 302- assert get_redirect_location(response) == reverse('cart:checkout-summary')---def test_shipping_method_without_shipping(- request_cart, product_without_shipping, client):- variant = product_without_shipping.variants.get()- add_variant_to_cart(request_cart, variant)-- response = client.get(reverse('cart:checkout-shipping-method'))- assert response.status_code == 302- assert get_redirect_location(response) == reverse('cart:checkout-summary')---def test_shipping_method_without_address(request_cart_with_item, client):- response = client.get(reverse('cart:checkout-shipping-method'))- assert response.status_code == 302- assert (- get_redirect_location(response) ==- reverse('cart:checkout-shipping-address'))---def test_summary_without_address(request_cart_with_item, client):- response = client.get(reverse('cart:checkout-summary'))- assert response.status_code == 302- assert (- get_redirect_location(response) == reverse('cart:checkout-shipping-method'))---def test_summary_without_shipping_method(- request_cart_with_item, client, monkeypatch):- response = client.get(reverse('cart:checkout-summary'))- assert response.status_code == 302- assert (- get_redirect_location(response) == reverse('cart:checkout-shipping-method'))---def test_email_is_saved_in_order(- authorized_client, customer_user, request_cart_with_item,- shipping_method):- # Prepare some data- request_cart_with_item.user = customer_user- request_cart_with_item.save()-- # Enter checkout- # Checkout index redirects directly to shipping address step- shipping_address = authorized_client.get(- reverse('cart:checkout-index'), follow=True)-- # Enter shipping address data- shipping_data = {'address': customer_user.default_billing_address.pk}- shipping_method_page = authorized_client.post(- shipping_address.request['PATH_INFO'], data=shipping_data, follow=True)-- # Select shipping method- shipping_method_data = {- 'shipping_method': shipping_method.price_per_country.first().pk}- shipping_method_response = authorized_client.post(- shipping_method_page.request['PATH_INFO'], data=shipping_method_data,- follow=True)-- # Summary page asks for Billing address, default is the same as shipping- payment_method_data = {'address': 'shipping_address'}- payment_method_page = authorized_client.post(- shipping_method_response.request['PATH_INFO'],- data=payment_method_data, follow=True)-- # After summary step, order is created and it waits for payment- order = payment_method_page.context['order']- assert order.user_email == customer_user.email---def test_voucher_invalid(- client, request_cart_with_item, shipping_method, voucher):- # related issues: #549 #544- voucher.usage_limit = 3- voucher.save()- # Enter checkout- checkout_index = client.get(reverse('cart:checkout-index'), follow=True)- # Checkout index redirects directly to shipping address step- shipping_address = client.get(checkout_index.request['PATH_INFO'])-- # Enter shipping address data- shipping_data = {- 'user_email': '[email protected]',- 'first_name': 'John',- 'last_name': 'Doe',- 'street_address_1': 'Aleje Jerozolimskie 2',- 'street_address_2': '',- 'city': 'Warszawa',- 'city_area': '',- 'country_area': '',- 'postal_code': '00-374',- 'country': 'PL'}- shipping_response = client.post(shipping_address.request['PATH_INFO'],- data=shipping_data, follow=True)-- # Select shipping method- shipping_method_page = client.get(shipping_response.request['PATH_INFO'])-- # Redirect to summary after shipping method selection- shipping_method_data = {- 'shipping_method': shipping_method.price_per_country.first().pk}- shipping_method_response = client.post(- shipping_method_page.request['PATH_INFO'], data=shipping_method_data,- follow=True)-- # Summary page asks for Billing address, default is the same as shipping- url = shipping_method_response.request['PATH_INFO']- discount_data = {'discount-voucher': voucher.code}- voucher_response = client.post(- '{url}?next={url}'.format(url=url), follow=True, data=discount_data,- HTTP_REFERER=url)- assert voucher_response.context['cart'].voucher_code == voucher.code- voucher.used = 3- voucher.save()- address_data = {'address': 'shipping_address'}- assert url == reverse('cart:checkout-summary')- summary_response = client.post(url, data=address_data, follow=True)- assert summary_response.context['cart'].voucher_code is None-- summary_response = client.post(url, data=address_data, follow=True)- assert summary_response.context['order'].voucher is None---def test_voucher_code_invalid(- client, request_cart_with_item, shipping_method):- # Enter checkout- checkout_index = client.get(reverse('cart:checkout-index'), follow=True)- # Checkout index redirects directly to shipping address step- shipping_address = client.get(checkout_index.request['PATH_INFO'])-- # Enter shipping address data- shipping_data = {- 'email': '[email protected]',- 'first_name': 'John',- 'last_name': 'Doe',- 'street_address_1': 'Aleje Jerozolimskie 2',- 'street_address_2': '',- 'city': 'Warszawa',- 'city_area': '',- 'country_area': '',- 'postal_code': '00-374',- 'country': 'PL'}- shipping_response = client.post(shipping_address.request['PATH_INFO'],- data=shipping_data, follow=True)-- # Select shipping method- shipping_method_page = client.get(shipping_response.request['PATH_INFO'])-- # Redirect to summary after shipping method selection- shipping_method_data = {- 'method': shipping_method.price_per_country.first().pk}- shipping_method_response = client.post(- shipping_method_page.request['PATH_INFO'], data=shipping_method_data,- follow=True)-- # Summary page asks for Billing address, default is the same as shipping- url = shipping_method_response.request['PATH_INFO']- discount_data = {'discount-voucher': 'invalid-code'}- voucher_response = client.post(- '{url}?next={url}'.format(url=url), follow=True, data=discount_data,- HTTP_REFERER=url)- assert voucher_response.status_code == 200- assert 'voucher' in voucher_response.context['voucher_form'].errors- assert voucher_response.context['cart'].voucher_code is None---def test_remove_voucher(- client, request_cart_with_item, shipping_method, voucher):- # Enter checkout- checkout_index = client.get(reverse('cart:checkout-index'), follow=True)- # Checkout index redirects directly to shipping address step- shipping_address = client.get(checkout_index.request['PATH_INFO'])-- # Enter shipping address data- shipping_data = {- 'email': '[email protected]',- 'first_name': 'John',- 'last_name': 'Doe',- 'street_address_1': 'Aleje Jerozolimskie 2',- 'street_address_2': '',- 'city': 'Warszawa',- 'city_area': '',- 'country_area': '',- 'postal_code': '00-374',- 'country': 'PL'}- shipping_response = client.post(shipping_address.request['PATH_INFO'],- data=shipping_data, follow=True)-- # Select shipping method- shipping_method_page = client.get(shipping_response.request['PATH_INFO'])-- # Redirect to summary after shipping method selection- shipping_method_data = {- 'method': shipping_method.price_per_country.first().pk}- shipping_method_response = client.post(- shipping_method_page.request['PATH_INFO'], data=shipping_method_data,- follow=True)-- # Summary page asks for Billing address, default is the same as shipping- url = shipping_method_response.request['PATH_INFO']- discount_data = {'discount-voucher': voucher.code}- voucher_response = client.post(- '{url}?next={url}'.format(url=url), follow=True, data=discount_data,- HTTP_REFERER=url)- assert voucher_response.context['cart'].voucher_code is not None- # Remove voucher from checkout- voucher_response = client.post(- reverse('cart:checkout-remove-voucher'), follow=True, HTTP_REFERER=url)- assert voucher_response.status_code == 200- assert voucher_response.context['cart'].voucher_code is None---def test_language_is_saved_in_order(- authorized_client, customer_user, request_cart_with_item, settings,- shipping_method):- # Prepare some data- settings.LANGUAGE_CODE = 'en'- user_language = 'fr'- request_cart_with_item.user = customer_user- request_cart_with_item.save()-- # Set user's language to fr- authorized_client.cookies[settings.LANGUAGE_COOKIE_NAME] = user_language- authorized_client.post(reverse('set_language'), data={'language': 'fr'})- # Enter checkout- # Checkout index redirects directly to shipping address step- shipping_address = authorized_client.get(- reverse('cart:checkout-index'), follow=True,- HTTP_ACCEPT_LANGUAGE=user_language)-- # Enter shipping address data- shipping_data = {'address': customer_user.default_billing_address.pk}- shipping_method_page = authorized_client.post(- shipping_address.request['PATH_INFO'], data=shipping_data, follow=True,- HTTP_ACCEPT_LANGUAGE=user_language)-- # Select shipping method- shipping_method_data = {- 'shipping_method': shipping_method.price_per_country.first().pk}- shipping_method_response = authorized_client.post(- shipping_method_page.request['PATH_INFO'], data=shipping_method_data,- follow=True, HTTP_ACCEPT_LANGUAGE=user_language)-- # Summary page asks for Billing address, default is the same as shipping- payment_method_data = {'address': 'shipping_address'}- payment_method_page = authorized_client.post(- shipping_method_response.request['PATH_INFO'],- data=payment_method_data, follow=True,- HTTP_ACCEPT_LANGUAGE=user_language)-- # After summary step, order is created and it waits for payment- order = payment_method_page.context['order']- assert order.language_code == user_language---def test_create_user_after_order(order, client):- order.user_email = '[email protected]'- order.save()- assert not User.objects.filter(email='[email protected]').exists()- data = {'password': 'password'}- url = reverse('order:checkout-success', kwargs={'token': order.token})- response = client.post(url, data=data)- redirect_location = get_redirect_location(response)- detail_url = reverse('order:details', kwargs={'token': order.token})- assert redirect_location == detail_url- user = User.objects.filter(email='[email protected]')- assert user.exists()- user = user.first()- assert user.orders.filter(token=order.token).exists()diff --git a/tests/test_order.py b/tests/test_order.pyindex 070f06532d..efafc2e3ec 100644--- a/tests/test_order.py+++ b/tests/test_order.py@@ -3,10 +3,13 @@ from decimal import Decimalfrom django.urls import reversefrom django_countries.fields import Country-from payments import PaymentStatus+from payments import FraudStatus, PaymentStatusfrom prices import Money, TaxedMoney+from tests.utils import get_redirect_location+from saleor.account.models import User+from saleor.cart.checkout.utils import create_orderfrom saleor.core.utils.taxes import (DEFAULT_TAX_RATE_NAME, get_tax_rate_by_name, get_taxes_for_country)from saleor.order import FulfillmentStatus, OrderStatus, models@@ -380,3 +383,72 @@ def test_update_order_prices(order_with_lines):total = (line_1.quantity * price_1 + line_2.quantity * price_2 + shipping_price)assert order_with_lines.total == total+++def test_order_payment_flow(+ request_cart_with_item, client, address, shipping_method):+ request_cart_with_item.shipping_address = address+ request_cart_with_item.billing_address = address.get_copy()+ request_cart_with_item.user_email = '[email protected]'+ request_cart_with_item.shipping_method = (+ shipping_method.price_per_country.first())+ request_cart_with_item.save()++ order = create_order(+ request_cart_with_item, 'tracking_code', discounts=None, taxes=None)++ # Select payment method+ url = reverse('order:payment', kwargs={'token': order.token})+ data = {'method': 'default'}+ response = client.post(url, data, follow=True)++ assert len(response.redirect_chain) == 1+ assert response.status_code == 200+ redirect_url = reverse(+ 'order:payment', kwargs={'token': order.token, 'variant': 'default'})+ assert response.request['PATH_INFO'] == redirect_url++ # Go to payment details page, enter payment data+ data = {+ 'status': PaymentStatus.PREAUTH,+ 'fraud_status': FraudStatus.UNKNOWN,+ 'gateway_response': '3ds-disabled',+ 'verification_result': 'waiting'}++ response = client.post(redirect_url, data)++ assert response.status_code == 302+ redirect_url = reverse(+ 'order:payment-success', kwargs={'token': order.token})+ assert get_redirect_location(response) == redirect_url++ # Complete payment, go to checkout success page+ data = {'status': 'ok'}+ response = client.post(redirect_url, data)+ assert response.status_code == 302+ redirect_url = reverse(+ 'order:checkout-success', kwargs={'token': order.token})+ assert get_redirect_location(response) == redirect_url++ # Assert that payment object was created and contains correct data+ payment = order.payments.all()[0]+ assert payment.total == order.total.gross.amount+ assert payment.tax == order.total.tax.amount+ assert payment.currency == order.total.currency+ assert payment.delivery == order.shipping_price.net.amount+ assert len(payment.get_purchased_items()) == len(order.lines.all())+++def test_create_user_after_order(order, client):+ order.user_email = '[email protected]'+ order.save()+ url = reverse('order:checkout-success', kwargs={'token': order.token})+ data = {'password': 'password'}++ response = client.post(url, data)++ redirect_url = reverse('order:details', kwargs={'token': order.token})+ assert get_redirect_location(response) == redirect_url+ user = User.objects.filter(email='[email protected]').first()+ assert user is not None+ assert user.orders.filter(token=order.token).exists()