Пример #1
0
 def test_get_line_total_multiple_quantity(self):
     '''get_line_total returns the correct price for item with multiple
     quantity.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple', 3)
     self.assertEqual(round(cartitem.get_line_total(product_store), 2),
                      float('0.45'))
Пример #2
0
 def test_get_line_total_multiple_quantity(self):
     '''get_line_total returns the correct price for item with multiple
     quantity.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple', 3)
     self.assertEqual(
         cartitem.get_line_total(product_store), Decimal('0.45'))
Пример #3
0
 def test_nooffer_total(self):
     '''NoOffer's calculate_line_total returns same value as cart item line
     total.'''
     product_store = self._create_product_store()
     no_offer_strawberries = NoOffer('strawberries')
     cartitem = CartItem('strawberries')
     self.assertEqual(cartitem.get_line_total(
         product_store), no_offer_strawberries.calculate_line_total(cartitem, product_store))
Пример #4
0
 def test_nooffer_total(self):
     '''NoOffer's calculate_line_total returns same value as cart item line
     total.'''
     product_store = self._create_product_store()
     no_offer_strawberries = NoOffer('strawberries')
     cartitem = CartItem('strawberries')
     self.assertEqual(
         cartitem.get_line_total(product_store),
         no_offer_strawberries.calculate_line_total(cartitem,
                                                    product_store))
Пример #5
0
 def test_bogof_one_item_six_quantity(self):
     '''Correct line total for item with 6 quantity.'''
     product_store = self._create_product_store()
     bogof_apples = MultiBuyOffer('apple', 1, 1)
     cartitem = CartItem('apple', 6)
     self.assertEqual(
         round(bogof_apples.calculate_line_total(cartitem, product_store),
               2), float('0.45'))
Пример #6
0
 def test_multibuy_eight_item_buy_5_2_free(self):
     '''Correct line total for item with 8 quantity (buy 5 get 2 free).'''
     product_store = self._create_product_store()
     multibuy_apples = MultiBuyOffer('apple', 5, 2)
     cartitem = CartItem('apple', 8)
     self.assertEqual(
         multibuy_apples.calculate_line_total(cartitem, product_store),
         Decimal('0.90'))
Пример #7
0
 def test_multibuy_seven_item_buy_2_1_free(self):
     '''Correct line total for item with 7 quantity (buy 2 get 1 free).'''
     product_store = self._create_product_store()
     multibuy_apples = MultiBuyOffer('apple', 2, 1)
     cartitem = CartItem('apple', 7)
     self.assertEqual(
         multibuy_apples.calculate_line_total(cartitem, product_store),
         Decimal('0.75'))
Пример #8
0
 def test_bogof_one_item_five_quantity(self):
     '''Correct line total for item with 5 quantity.'''
     product_store = self._create_product_store()
     bogof_apples = MultiBuyOffer('apple', 1, 1)
     cartitem = CartItem('apple', 5)
     self.assertEqual(
         bogof_apples.calculate_line_total(cartitem, product_store),
         Decimal('0.45'))
Пример #9
0
 def test_multibuy_seven_item_buy_5_2_free(self):
     '''Correct line total for item with 7 quantity (buy 5 get 2 free).'''
     product_store = self._create_product_store()
     multibuy_apples = MultiBuyOffer('apple', 5, 2)
     cartitem = CartItem('apple', 7)
     self.assertEqual(
         round(
             multibuy_apples.calculate_line_total(cartitem, product_store),
             2), float('0.75'))
Пример #10
0
 def test_multibuy_six_item_buy_2_1_free(self):
     '''Correct line total for item with 6 quantity (buy 2 get 1 free).'''
     product_store = self._create_product_store()
     multibuy_apples = MultiBuyOffer('apple', 2, 1)
     cartitem = CartItem('apple', 6)
     self.assertEqual(
         round(
             multibuy_apples.calculate_line_total(cartitem, product_store),
             2), float('0.60'))
Пример #11
0
def do_cart(request):

    # hiddenのitem_idを取得しintに型変換
    item_id = int(request.POST['item_id'])
    item = Item.objects.get(id=item_id)

    # DBからItem情報を取得する。
    cart_item_list = request.session.get('cart_item_list',[])
    ci = CartItem()
    ci.item_id = item_id
    ci.item_code = item.item_code
    ci.item_name = item.item_name
    ci.price = item.price
    ci.buy_num = request.POST['buy_num']
    cart_item_list.append(ci)
    request.session['cart_item_list'] = cart_item_list

    return render_to_response('page/cart_item_list.html',
                    RequestContext(request, {'cart_item_list': cart_item_list}))
Пример #12
0
def item(label=None, quantity=None):
    return CartItem(label=label or any_label(), quantity=quantity or any_quantity())
Пример #13
0
 def test_get_line_total_is_decimal(self):
     '''Cart.get_line_total() returns a Decimal.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple')
     self.assertTrue(
         type(cartitem.get_line_total(product_store) is Decimal))
Пример #14
0
 def test_get_line_total(self):
     '''Cart.get_line_total() returns the correct price for product.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple')
     self.assertEqual(round(cartitem.get_line_total(product_store), 2),
                      float('0.15'))
Пример #15
0
 def test_quantity_on_create_with_value(self):
     '''Creating a CartItem with a passed quantity initialises with that
     quantity.'''
     cartitem = CartItem('apple', 3)
     self.assertEqual(cartitem.quantity, 3)
Пример #16
0
 def test_quantity_on_create_with_no_value(self):
     '''Creating a CartItem without passing a quantity initialises quantity
     with 1.'''
     cartitem = CartItem('apple')
     self.assertEqual(cartitem.quantity, 1)
Пример #17
0
 def test_get_line_total_is_float(self):
     '''Cart.get_line_total() returns a float.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple')
     self.assertTrue(
         type(round(cartitem.get_line_total(product_store), 2) is float))
Пример #18
0
 def test_get_line_total(self):
     '''Cart.get_line_total() returns the correct price for product.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple')
     self.assertEqual(
         cartitem.get_line_total(product_store), Decimal('0.15'))
Пример #19
0
def item(reference=None, quantity=None):
    return CartItem(reference=reference or any_reference(), quantity=quantity or any_quantity())
Пример #20
0
 def test_get_line_total_is_decimal(self):
     '''Cart.get_line_total() returns a Decimal.'''
     product_store = self._create_product_store()
     cartitem = CartItem('apple')
     self.assertTrue(
         type(cartitem.get_line_total(product_store) is Decimal))