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'))
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'))
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))
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))
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'))
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'))
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'))
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'))
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'))
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'))
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}))
def item(label=None, quantity=None): return CartItem(label=label or any_label(), quantity=quantity or any_quantity())
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))
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'))
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)
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)
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))
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'))
def item(reference=None, quantity=None): return CartItem(reference=reference or any_reference(), quantity=quantity or any_quantity())