コード例 #1
0
 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)
コード例 #2
0
 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()),[])
コード例 #3
0
 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()), [])
コード例 #4
0
 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)
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
 def test_cart_shipping_timer_unpaid(self):
     cart = get_cart(FakeRequest())
     self.assertFalse(cart.ready_for_ship())
     self.assertEqual(cart.ready_at(),"Not Paid!")
コード例 #8
0
    def test_get_cart_known_uuid(self):

        cart = get_cart(FakeRequest())
        self.assertEqual(cart.owner,"hello_world")
コード例 #9
0
 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()
コード例 #10
0
 def test_cart_shipping_timer_unpaid(self):
     cart = get_cart(FakeRequest())
     self.assertFalse(cart.ready_for_ship())
     self.assertEqual(cart.ready_at(), "Not Paid!")
コード例 #11
0
    def test_get_cart_known_uuid(self):

        cart = get_cart(FakeRequest())
        self.assertEqual(cart.owner, "hello_world")