def test_standard_product(self): session = SessionStore() rf = RequestFactory() request = rf.post("/", {"product_id": self.p0.id, "quantity": 1}) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) # 1l login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(cart, None) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) # logout session = SessionStore() request = rf.post("/", {"product_id": self.p0.id, "quantity": 2}) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 2) # 2. login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 3)
def test_ga_ecommerce_tracking(self): """ """ shop = lfs.core.utils.get_default_shop() shop.google_analytics_id = "" shop.ga_site_tracking = False shop.ga_ecommerce_tracking = False shop.save() session = SessionStore() rf = RequestFactory() request = rf.get('/') request.session = session template = get_template_from_string( """{% load lfs_tags %}{% google_analytics_ecommerce %}""") content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # Enter a google_analytics_id shop.google_analytics_id = "UA-XXXXXXXXXX" shop.save() # Simulating a new request rf = RequestFactory() request = rf.get('/') request.session = session # But this is not enough content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # It has to be activated first shop.ga_ecommerce_tracking = True shop.save() # Simulating a new request rf = RequestFactory() request = rf.get('/') request.session = session # But this is still not enough content = template.render(Context({"request": request})) self.failIf(content.find("pageTracker") != -1) # There has to be an order within the session session["order"] = Order() # Now it works and "pageTracker" is found content = template.render(Context({"request": request})) self.failIf(content.find("_trackPageview") == -1)
def test_manage_urls_anonymous(self): """Tests that all manage urls cannot accessed by anonymous user. """ rf = RequestFactory() request = rf.get("/") request.user = AnonymousUser() from lfs.manage.urls import urlpatterns for url in urlpatterns: result = url.callback(request) self.failUnless(result["Location"].startswith("/login/?next=/"))
def setUp(self): """ """ session = SessionStore() session.save() rf = RequestFactory() self.request = rf.get('/') self.request.session = session self.request.user = AnonymousUser() tax = Tax.objects.create(rate=19) shipping_method = ShippingMethod.objects.create( name="Standard", active=True, price=1.0, tax=tax ) payment_method = PaymentMethod.objects.create( name="Direct Debit", active=True, tax=tax, ) us = Country.objects.get(code="us") ie = Country.objects.get(code="ie") address1 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=ie, phone="555-111111", email="*****@*****.**", ) address2 = Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="Smallville", zip_code="2443", country=us, phone="666-111111", email="*****@*****.**", ) address3 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=ie, phone="555-111111", email="*****@*****.**", ) address4 = Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="Smallville", zip_code="2443", country=us, phone="666-111111", email="*****@*****.**", ) self.customer = Customer.objects.create( session=session.session_key, selected_shipping_method=shipping_method, selected_payment_method=payment_method, selected_shipping_address=address1, selected_invoice_address=address2, default_shipping_address=address1, default_invoice_address=address2, ) self.p1 = Product.objects.create( name="Product 1", slug="product-1", sku="sku-1", price=1.1, tax=tax, active=True, ) self.p2 = Product.objects.create( name="Product 2", slug="product-2", sku="sku-2", price=2.2, tax=tax, active=True, ) cart = Cart.objects.create( session=session.session_key ) item = CartItem.objects.create( cart=cart, product=self.p1, amount=2, ) item = CartItem.objects.create( cart=cart, product=self.p2, amount=3, )
def setUp(self): """ """ session = SessionStore() session.save() rf = RequestFactory() self.request = rf.get('/') self.request.session = session self.request.user = AnonymousUser() tax = Tax.objects.create(rate=19) delivery_time = DeliveryTime.objects.create(min=3, max=10) shipping_method = ShippingMethod.objects.create( name="Standard", active=True, price=1.0, tax=tax, delivery_time=delivery_time) payment_method = PaymentMethod.objects.create( name="Direct Debit", active=True, tax=tax, ) us = Country.objects.get(code="us") ie = Country.objects.get(code="ie") address1 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=ie, phone="555-111111", email="*****@*****.**", ) address2 = Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="Smallville", zip_code="2443", country=us, phone="666-111111", email="*****@*****.**", ) Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=ie, phone="555-111111", email="*****@*****.**", ) Address.objects.create( firstname="Jane", lastname="Doe", company_name="Doe Ltd.", line1="Street 43", city="Smallville", zip_code="2443", country=us, phone="666-111111", email="*****@*****.**", ) self.customer = Customer.objects.create( session=session.session_key, selected_shipping_method=shipping_method, selected_payment_method=payment_method, selected_shipping_address=address1, selected_invoice_address=address2, default_shipping_address=address1, default_invoice_address=address2, ) self.p1 = Product.objects.create( name="Product 1", slug="product-1", sku="sku-1", price=1.1, tax=tax, active=True, ) self.p2 = Product.objects.create( name="Product 2", slug="product-2", sku="sku-2", price=2.2, tax=tax, active=True, ) cart = Cart.objects.create(session=session.session_key) CartItem.objects.create( cart=cart, product=self.p1, amount=2, ) CartItem.objects.create( cart=cart, product=self.p2, amount=3, )
def test_configurable_product(self): rf = RequestFactory() session = SessionStore() request = rf.post( "/", { "product_id": self.p1.id, "quantity": 1, "property-%s" % self.pp1.id: "A" }) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) request = rf.post( "/", { "product_id": self.p1.id, "quantity": 10, "property-%s" % self.pp1.id: "B" }) request.session = session request.user = AnonymousUser() add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) # 1. login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(cart, None) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) # logout session = SessionStore() request = rf.post( "/", { "product_id": self.p1.id, "quantity": 2, "property-%s" % self.pp1.id: "A" }) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 2) request = rf.post( "/", { "product_id": self.p1.id, "quantity": 20, "property-%s" % self.pp1.id: "B" }) request.session = session request.user = AnonymousUser() add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 2) self.assertEqual(int(cart.get_items()[1].amount), 20) # 2. login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 3) self.assertEqual(int(cart.get_items()[1].amount), 30)
def setUp(self): """ """ session = SessionStore() rf = RequestFactory() self.request = rf.get('/') self.request.session = session self.request.user = AnonymousUser() tax = Tax.objects.create(rate=19) discount = Discount.objects.create(name="Summer", value=10.0, type=0, tax=tax) shipping_method = ShippingMethod.objects.create( name="Standard", active=True, price=1.0, tax=tax ) payment_method = PaymentMethod.objects.create( name="Direct Debit", active=True, tax=tax, ) us = Country.objects.get(code="us") address1 = Address.objects.create( firstname="John", lastname="Doe", company_name="Doe Ltd.", line1="Street 42", city="Gotham City", zip_code="2342", country=us, phone="555-111111", email="*****@*****.**", ) self.customer = Customer.objects.create( session=session.session_key, selected_shipping_method=shipping_method, selected_payment_method=payment_method, selected_shipping_address=address1, selected_invoice_address=address1, ) self.p1 = Product.objects.create( name="Product 1", slug="product-1", sku="sku-1", price=1.1, tax=tax, active=True, ) self.p2 = Product.objects.create( name="Product 2", slug="product-2", sku="sku-2", price=2.2, tax=tax, active=True, ) cart = Cart.objects.create( session=session.session_key ) item = CartItem.objects.create( cart=cart, product=self.p1, amount=2, ) item = CartItem.objects.create( cart=cart, product=self.p2, amount=3, )
def test_configurable_product(self): rf = RequestFactory() session = SessionStore() request = rf.post("/", {"product_id": self.p1.id, "quantity": 1, "property-%s" % self.pp1.id: "A"}) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) request = rf.post("/", {"product_id": self.p1.id, "quantity": 10, "property-%s" % self.pp1.id: "B"}) request.session = session request.user = AnonymousUser() add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) # 1. login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(cart, None) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) # logout session = SessionStore() request = rf.post("/", {"product_id": self.p1.id, "quantity": 2, "property-%s" % self.pp1.id: "A"}) request.session = session request.user = AnonymousUser() cart = get_cart(request) self.assertEqual(cart, None) add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 2) request = rf.post("/", {"product_id": self.p1.id, "quantity": 20, "property-%s" % self.pp1.id: "B"}) request.session = session request.user = AnonymousUser() add_to_cart(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 2) self.assertEqual(int(cart.get_items()[1].amount), 20) # 2. login admin request = rf.get("/") request.session = session request.user = self.admin cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 1) self.assertEqual(int(cart.get_items()[1].amount), 10) update_cart_after_login(request) cart = get_cart(request) self.assertEqual(int(cart.get_items()[0].amount), 3) self.assertEqual(int(cart.get_items()[1].amount), 30)