def test_cart_shipping_timer_ready(self): cart = get_cart(FakeRequest()) cart.timestamp = int(time.time())-ONE_HOUR*24-1 self.assertTrue(cart.ready_for_ship()) format_string="%x %X" expect = datetime.datetime.fromtimestamp(cart.timestamp+ONE_HOUR*24).strftime(format_string) self.assertEqual(cart.ready_at(format_string),expect)
def test_get_cart_normal_request(self): response = self.client.get("/") request = response.wsgi_request cart = get_cart(request) self.assertEqual(cart.owner,request.session.get("uuid","")) self.assertEqual(cart.total_count(),0) self.assertEqual(cart.total_cost(),0) self.assertEqual(list(cart.items.all()),[])
def test_get_cart_normal_request(self): response = self.client.get("/") request = response.wsgi_request cart = get_cart(request) self.assertEqual(cart.owner, request.session.get("uuid", "")) self.assertEqual(cart.total_count(), 0) self.assertEqual(cart.total_cost(), 0) self.assertEqual(list(cart.items.all()), [])
def test_cart_shipping_timer_ready(self): cart = get_cart(FakeRequest()) cart.timestamp = int(time.time()) - ONE_HOUR * 24 - 1 self.assertTrue(cart.ready_for_ship()) format_string = "%x %X" expect = datetime.datetime.fromtimestamp(cart.timestamp + ONE_HOUR * 24).strftime(format_string) self.assertEqual(cart.ready_at(format_string), expect)
def add_product_to_cart(request, product_id): data = {} try: product = Product.objects.get(pk=product_id) except ObjectDoesNotExist: data = {"status": "Fail"} else: data = {"status": "OK"} cart = get_cart(request) cart.add_product(product) cart.save() data.update(get_cart_dict(request)) return JsonResponse(data)
def update_cart(request, product_id, qty): data = {} try: product = Product.objects.get(pk=product_id) except ObjectDoesNotExist: data = {"status": "Fail"} else: data = {"status": "OK"} cart = get_cart(request) item, _ = CartItem.objects.get_or_create(cart=cart, product=product) item.quantity = qty item.save() data.update(get_cart_dict(request)) return JsonResponse(data)
def test_cart_shipping_timer_unpaid(self): cart = get_cart(FakeRequest()) self.assertFalse(cart.ready_for_ship()) self.assertEqual(cart.ready_at(),"Not Paid!")
def test_get_cart_known_uuid(self): cart = get_cart(FakeRequest()) self.assertEqual(cart.owner,"hello_world")
def setUp(self): self.cart = get_cart(FakeRequest()) self.product = Product(product_name="test1",product_description="",product_cost=2.25,product_ingredients="") self.product.save() self.product2 = Product(product_name="test2",product_description="",product_cost=2.50,product_ingredients="") self.product2.save()
def test_cart_shipping_timer_unpaid(self): cart = get_cart(FakeRequest()) self.assertFalse(cart.ready_for_ship()) self.assertEqual(cart.ready_at(), "Not Paid!")
def test_get_cart_known_uuid(self): cart = get_cart(FakeRequest()) self.assertEqual(cart.owner, "hello_world")