예제 #1
0
def test_adding_to_cart_with_closed_cart_token(admin_user, admin_client,
                                               product_in_stock):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=admin_user)
    variant = product_in_stock.variants.first()
    cart.add(variant, 1)
    cart.change_status(CartStatus.ORDERED)

    response = client.get('/cart/')
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={
                    'slug': product_in_stock.get_slug(),
                    'product_id': product_in_stock.pk
                }), {
                    'quantity': 1,
                    'variant': variant.pk
                })

    assert Cart.objects.filter(user=admin_user,
                               status=CartStatus.OPEN).count() == 1
    assert Cart.objects.filter(user=admin_user,
                               status=CartStatus.ORDERED).count() == 1
예제 #2
0
def test_adding_to_cart_with_another_user_token(admin_user, admin_client,
                                                product_in_stock,
                                                customer_user):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=customer_user)
    variant = product_in_stock.variants.first()
    cart.add(variant, 1)

    response = client.get('/cart/')
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={
                    'slug': product_in_stock.get_slug(),
                    'product_id': product_in_stock.pk
                }), {
                    'quantity': 1,
                    'variant': variant.pk
                })

    assert Cart.objects.count() == 2
    assert Cart.objects.get(user=admin_user).pk != cart.pk
예제 #3
0
def test_adding_to_cart_with_deleted_cart_token(admin_user, admin_client,
                                                product_in_stock):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=admin_user)
    old_token = cart.token
    variant = product_in_stock.variants.first()
    cart.add(variant, 1)

    response = client.get('/cart/')
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]
    cart.delete()

    client.post(
        reverse('product:add-to-cart',
                kwargs={
                    'slug': product_in_stock.get_slug(),
                    'product_id': product_in_stock.pk
                }), {
                    'quantity': 1,
                    'variant': variant.pk
                })

    assert Cart.objects.count() == 1
    assert not Cart.objects.filter(token=old_token).exists()
예제 #4
0
def bullets_run_reminder(request, uuid):
	runner = get_object_or_404(BulletsRunner, unique_url=uuid)
	
	if runner.paid():
		messages.info(request, 'You have already paid for the Bullets Run!')
		return redirect(reverse('index'))


	messages.info(request, 'Please complete the checkout process to finish your Bullets Run registration')
	if runner.race == '5':
		v_pk = 373	# variant PK for the 5k run
	else:
		v_pk = 374	# variant PK for the 10k run

	variant = ProductVariant.objects.get(pk=v_pk)	

	cart = get_cart_from_request(request, create=True)
	response = HttpResponseRedirect("/bullets-shop/checkout/")		# to avoid cheeky folk adding multiple tickets
		
	if not request.user.is_authenticated():
        	set_cart_cookie(cart, response)

	cart.add(variant, replace=True)
	request.session["bulletsRun"] = runner.id
	
	return response	
예제 #5
0
def bullets_run_register(request):
	if request.method == 'POST':
        	# create a form instance and populate it with data from the request:
		run_form = BulletsRunnerForm (request.POST)
        	# check whether it's valid:
		if run_form.is_valid():
			# Save the runner in the DB, then direct onwards to the shop
			runner = run_form.save()
			messages.info(request, 'Please complete the checkout process to finish your Bullets Run registration')

			if runner.race == '5':
				v_pk = 373	# variant PK for the 5k run
			else:
				v_pk = 374	# variant PK for the 10k run

			variant = ProductVariant.objects.get(pk=v_pk)	

			cart = get_cart_from_request(request, create=True)
			response = HttpResponseRedirect("/bullets-shop/checkout/")		# to avoid cheeky folk adding multiple tickets
		
			if not request.user.is_authenticated():
               			set_cart_cookie(cart, response)

			cart.add(variant)
			request.session["bulletsRun"] = runner.id
	
			return response	
			
  
	else:
        	run_form = BulletsRunnerForm()
  
	return render(request, "bullets/bullets_run_register.html", {'run_form':run_form})
예제 #6
0
def test_anonymous_adding_to_cart_with_another_user_token(
        client, product_in_stock, customer_user):
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=customer_user)
    variant = product_in_stock.variants.first()
    cart.add(variant, 1)

    response = client.get('/cart/')
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={'slug': product_in_stock.get_slug(),
                        'product_id': product_in_stock.pk}),
        {'quantity': 1, 'variant': variant.pk})

    assert Cart.objects.count() == 2
    assert Cart.objects.get(user=None).pk != cart.pk
예제 #7
0
def test_anonymous_adding_to_cart_with_another_user_token(
        client, product, customer_user):
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=customer_user)
    variant = product.variants.first()
    cart.add(variant, 1)

    response = client.get(reverse('cart:index'))
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={'slug': product.get_slug(),
                        'product_id': product.pk}),
        {'quantity': 1, 'variant': variant.pk})

    assert Cart.objects.count() == 2
    assert Cart.objects.get(user=None).pk != cart.pk
예제 #8
0
def test_adding_to_cart_with_current_user_token(
        admin_user, admin_client, product_in_stock):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=admin_user)
    variant = product_in_stock.variants.first()
    cart.add(variant, 1)

    response = client.get('/cart/')
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={'slug': product_in_stock.get_slug(),
                        'product_id': product_in_stock.pk}),
        {'quantity': 1, 'variant': variant.pk})

    assert Cart.objects.count() == 1
    assert Cart.objects.get(user=admin_user).pk == cart.pk
예제 #9
0
def test_adding_to_cart_with_current_user_token(
        admin_user, admin_client, product):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=admin_user)
    variant = product.variants.first()
    cart.add(variant, 1)

    response = client.get(reverse('cart:index'))
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={'slug': product.get_slug(),
                        'product_id': product.pk}),
        {'quantity': 1, 'variant': variant.pk})

    assert Cart.objects.count() == 1
    assert Cart.objects.get(user=admin_user).pk == cart.pk
예제 #10
0
def test_adding_to_cart_with_closed_cart_token(
        admin_user, admin_client, product):
    client = admin_client
    key = utils.COOKIE_NAME
    cart = Cart.objects.create(user=admin_user)
    variant = product.variants.first()
    cart.add(variant, 1)

    response = client.get(reverse('cart:index'))
    utils.set_cart_cookie(cart, response)
    client.cookies[key] = response.cookies[key]

    client.post(
        reverse('product:add-to-cart',
                kwargs={'slug': product.get_slug(),
                        'product_id': product.pk}),
        {'quantity': 1, 'variant': variant.pk})

    assert Cart.objects.filter(
        user=admin_user, status=CartStatus.OPEN).count() == 1