Skip to content

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

Use request_cart fixture in check intergration tests

Maciek Jabłoński6e1e01dec683
diff --git a/tests/conftest.py b/tests/conftest.py
index d7f4e29339..617c4cfbf0 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,10 +3,25 @@ from __future__ import unicode_literals
import pytest
+from saleor.cart import decorators
+from saleor.cart.models import Cart
from saleor.product.models import Product, ProductVariant, Stock
from saleor.userprofile.models import Address, User
+
+def cart(db): # pylint: disable=W0613
+ return Cart.objects.create()
+
+
+def request_cart(cart, monkeypatch):
+ monkeypatch.setattr(
+ decorators, 'get_cart_from_request',
+ lambda request, create=False: cart)
+ return cart
+
@pytest.fixture()
def admin_user(db):
"""A Django admin user.
diff --git a/tests/test_cart.py b/tests/test_cart.py
index 9475b7cc07..c1de225251 100644
--- a/tests/test_cart.py
+++ b/tests/test_cart.py
@@ -12,19 +12,6 @@ from saleor.cart.models import Cart
from satchless.item import InsufficientStock
-def cart(db): # pylint: disable=W0613
- return Cart.objects.create()
-
-
-def request_cart(cart, monkeypatch):
- monkeypatch.setattr(
- decorators, 'get_cart_from_request',
- lambda request, create=False: cart)
- return cart
-
-
def test_adding_without_checking(cart, product_in_stock):
variant = product_in_stock.variants.get()
cart.add(variant, 1000, check_quantity=False)
diff --git a/tests/test_checkout_integration.py b/tests/test_checkout_integration.py
index 608f102d2d..6f09699237 100644
--- a/tests/test_checkout_integration.py
+++ b/tests/test_checkout_integration.py
@@ -10,15 +10,10 @@ from saleor.shipping.models import ShippingMethod
@pytest.fixture
-def client_with_cart(product_in_stock, client):
+def client_with_cart(product_in_stock, request_cart, client):
variant = product_in_stock.variants.get()
# Prepare some data
- base_cart = Cart.objects.create()
- base_cart.add(variant)
-
- value = signing.get_cookie_signer(salt=Cart.COOKIE_NAME).sign(base_cart.token)
- client.cookies[Cart.COOKIE_NAME] = value
- client.cart = base_cart
+ request_cart.add(variant)
return client
@@ -178,14 +173,12 @@ def test_summary_without_shipping_method(client_with_cart, monkeypatch):
assert_redirect(response, reverse('checkout:shipping-method'))
-def test_client_login(client_with_cart, admin_user, monkeypatch):
+def test_client_login(request_cart, client_with_cart, admin_user):
data = {
'username': admin_user.email,
'password': 'password'
}
- assert Cart.objects.filter(user=admin_user).count() == 0
response = client_with_cart.post(reverse('registration:login'), data=data)
assert_redirect(response, '/')
- assert Cart.objects.filter(user=admin_user).count() == 1
response = client_with_cart.get(reverse('checkout:shipping-address'))
- assert response.context['checkout'].cart.token == client_with_cart.cart.token
+ assert response.context['checkout'].cart.token == request_cart.token