def test_view_invalid_update_cart(monkeypatch, client, cart, product_in_stock): variant = product_in_stock.variants.get() cart.add(variant, 1) monkeypatch.setattr(decorators, 'get_cart_from_request', lambda request: cart) request = client.post('/cart/update/{}'.format(variant.pk), {}) request.discounts = None request.POST = {} request.is_ajax = lambda: True # pylint: disable=E1120 response = views.update(request, variant.pk) resp_decoded = json.loads(response.content.decode('utf-8')) assert response.status_code == 400 assert 'error' in resp_decoded.keys() assert cart.quantity == 1
def test_view_update_cart_quantity(monkeypatch, client, cart, product_in_stock): variant = product_in_stock.variants.get() cart.add(variant, 1) monkeypatch.setattr(decorators, 'get_cart_from_request', lambda request: cart) request = client.post('/cart/update/{}'.format(variant.pk), {'quantity': 3}) request.discounts = None request.POST = {'quantity': 3} request.is_ajax = lambda: True # pylint: disable=E1120 response = views.update(request, variant.pk) assert response.status_code == 200 assert cart.quantity == 3
def test_view_invalid_update_cart(monkeypatch, client, cart, product_in_stock): variant = product_in_stock.variants.get() cart.add(variant, 1) monkeypatch.setattr( decorators, 'get_cart_from_request', lambda request: cart) request = client.post('/cart/update/{}'.format(variant.pk), {}) request.discounts = None request.POST = {} request.is_ajax = lambda: True # pylint: disable=E1120 response = views.update(request, variant.pk) resp_decoded = json.loads(response.content.decode('utf-8')) assert response.status_code == 400 assert 'error' in resp_decoded.keys() assert cart.quantity == 1
def test_view_update_cart_quantity( monkeypatch, client, cart, product_in_stock): variant = product_in_stock.variants.get() cart.add(variant, 1) monkeypatch.setattr( decorators, 'get_cart_from_request', lambda request: cart) request = client.post( '/cart/update/{}'.format(variant.pk), {'quantity': 3}) request.discounts = None request.POST = {'quantity': 3} request.is_ajax = lambda: True # pylint: disable=E1120 response = views.update(request, variant.pk) assert response.status_code == 200 assert cart.quantity == 3
def test_update_view_must_be_ajax(customer_user, rf): request = rf.post('/') request.user = customer_user request.discounts = None result = update(request, 1) assert result.status_code == 302