Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tests

akjanik945910d2e670
diff --git a/saleor/checkout/views/summary.py b/saleor/checkout/views/summary.py
index 8506bb79a5..7f0cf8eef9 100644
--- a/saleor/checkout/views/summary.py
+++ b/saleor/checkout/views/summary.py
@@ -124,7 +124,6 @@ def anonymous_summary_without_shipping(request, checkout):
note_form = NoteForm(request.POST or None)
if note_form.is_valid():
checkout.note = note_form.cleaned_data['note']
-
user_form = AnonymousUserBillingForm(
request.POST or None, initial={'email': checkout.email})
billing_address = checkout.billing_address
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 29c007933d..052450718b 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -1,13 +1,19 @@
-from unittest.mock import MagicMock, Mock
+from unittest.mock import MagicMock, Mock, patch
from django.conf import settings
from django.contrib.auth.models import AnonymousUser
+from django.test.client import RequestFactory
from prices import Price
import pytest
from satchless.item import InsufficientStock
from saleor.checkout import views
from saleor.checkout.core import STORAGE_SESSION_KEY, Checkout
+from saleor.checkout.views.summary import (
+ anonymous_summary_without_shipping,
+ summary_with_shipping_view,
+ summary_without_shipping)
+
from saleor.shipping.models import ShippingMethodCountry
from saleor.userprofile.models import Address
@@ -218,3 +224,37 @@ def test_checkout_create_order_insufficient_stock(
checkout = Checkout(request_cart, customer_user, 'tracking_code')
with pytest.raises(InsufficientStock):
checkout.create_order()
+
+
+ summary_without_shipping,
+ summary_with_shipping_view,
+ anonymous_summary_without_shipping,
+])
+@patch('saleor.checkout.views.summary.get_address_form',
+ return_value=(Mock(), Mock()))
+@patch('saleor.checkout.views.summary.BillingWithoutShippingAddressForm')
+@patch('saleor.checkout.views.summary.get_billing_forms_with_shipping',
+ return_value=(Mock(), Mock(), None))
+def test_note_ins_summary_views(
+ mock_get_billing_forms_with_shipping,
+ mock_BillingWithoutShippingAddressForm, mock_get_address_form, view):
+ checkout = Checkout(Mock(), Mock(
+ default_billing_address=Mock(),
+ addresses=Mock(is_authenticated=Mock(return_value=True))),
+ 'tracking_code')
+ rf = RequestFactory()
+ request = rf.post('/test/', {'note': 'test_note'})
+ request.user = Mock()
+ request.country = Mock()
+ mock_BillingWithoutShippingAddressForm().is_valid.return_value = False
+ view(request, checkout)
+ assert checkout.note == 'test_note'
+
+
+def test_note_in_created_order(request_cart, customer_user, billing_address):
+ customer_user.default_billing_address = billing_address
+ checkout = Checkout(request_cart, customer_user, 'tracking_code')
+ checkout.note = 'test_note'
+ order = checkout.create_order()
+ assert order.notes.values()[0].get('content') == 'test_note'