예제 #1
0
def test_adding_to_cart_with_deleted_cart_token(customer_user,
                                                authorized_client, product,
                                                request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()
    old_token = request_cart_with_item.token

    response = authorized_client.get(reverse('cart:index'))

    utils.set_cart_cookie(request_cart_with_item, response)
    authorized_client.cookies[key] = response.cookies[key]
    request_cart_with_item.delete()
    variant = product.variants.get()
    url = reverse('product:add-to-cart',
                  kwargs={
                      'slug': product.get_slug(),
                      'product_id': product.pk
                  })
    data = {'quantity': 1, 'variant': variant.pk}

    authorized_client.post(url, data)

    assert Cart.objects.count() == 1
    assert not Cart.objects.filter(token=old_token).exists()
예제 #2
0
def test_adding_to_cart_with_closed_cart_token(
        customer_user, authorized_client, product, request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()

    response = authorized_client.get(reverse('cart:index'))
    utils.set_cart_cookie(request_cart_with_item, response)
    authorized_client.cookies[key] = response.cookies[key]
    variant = product.variants.get()
    url = reverse(
        'product:add-to-cart',
        kwargs={'slug': product.get_slug(), 'product_id': product.pk})
    data = {'quantity': 1, 'variant': variant.pk}

    authorized_client.post(url, data)

    assert customer_user.carts.count() == 1
예제 #3
0
def test_adding_to_cart_with_closed_cart_token(
        customer_user, authorized_client, product, request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()

    response = authorized_client.get(reverse('cart:index'))
    utils.set_cart_cookie(request_cart_with_item, response)
    authorized_client.cookies[key] = response.cookies[key]
    variant = product.variants.get()
    url = reverse(
        'product:add-to-cart',
        kwargs={'slug': product.get_slug(), 'product_id': product.pk})
    data = {'quantity': 1, 'variant': variant.pk}

    authorized_client.post(url, data)

    assert customer_user.carts.count() == 1
예제 #4
0
def test_anonymous_adding_to_cart_with_another_user_token(
        client, product, customer_user, request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()

    response = client.get(reverse('cart:index'))

    utils.set_cart_cookie(request_cart_with_item, response)
    client.cookies[key] = response.cookies[key]
    variant = product.variants.get()
    url = reverse(
        'product:add-to-cart',
        kwargs={'slug': product.get_slug(), 'product_id': product.pk})
    data = {'quantity': 1, 'variant': variant.pk}

    client.post(url, data)

    assert Cart.objects.count() == 2
    assert Cart.objects.get(user=None).pk != request_cart_with_item.pk
예제 #5
0
def test_anonymous_adding_to_cart_with_another_user_token(
        client, product, customer_user, request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()

    response = client.get(reverse('cart:index'))

    utils.set_cart_cookie(request_cart_with_item, response)
    client.cookies[key] = response.cookies[key]
    variant = product.variants.get()
    url = reverse(
        'product:add-to-cart',
        kwargs={'slug': product.get_slug(), 'product_id': product.pk})
    data = {'quantity': 1, 'variant': variant.pk}

    client.post(url, data)

    assert Cart.objects.count() == 2
    assert Cart.objects.get(user=None).pk != request_cart_with_item.pk
예제 #6
0
def test_adding_to_cart_with_deleted_cart_token(
        customer_user, authorized_client, product, request_cart_with_item):
    key = utils.COOKIE_NAME
    request_cart_with_item.user = customer_user
    request_cart_with_item.save()
    old_token = request_cart_with_item.token

    response = authorized_client.get(reverse('cart:index'))

    utils.set_cart_cookie(request_cart_with_item, response)
    authorized_client.cookies[key] = response.cookies[key]
    request_cart_with_item.delete()
    variant = product.variants.get()
    url = reverse(
        'product:add-to-cart',
        kwargs={'slug': product.get_slug(), 'product_id': product.pk})
    data = {'quantity': 1, 'variant': variant.pk}

    authorized_client.post(url, data)

    assert Cart.objects.count() == 1
    assert not Cart.objects.filter(token=old_token).exists()