def test_item_after_load_products(self): '''An item's price can be retrieved from a ProductStore that's been created from a json file.''' json_file = os.path.abspath('test_products.json') product_store = ProductStore.load_products(json_file) self.assertEqual(product_store.get_product_price('apple'), float('0.15'))
def test_init_from_filepath(self): """ ProductStore object can be created from csv file. """ csv_filepath = os.path.abspath('catalogue.csv') product_store = ProductStore.init_from_filepath(csv_filepath) self.assertEqual(len(product_store.items), 6)
def test_item_after_init_from_filepath(self): '''An item's price can be retrieved from a ProductStore that's been created from a csv file.''' csv_filepath = os.path.abspath('test_products.csv') product_store = ProductStore.init_from_filepath(csv_filepath) self.assertEqual( product_store.get_product_price('apple'), Decimal('0.15'))
def _create_product_store(self): '''Helper method to create populated ProductStore.''' products = [('apple', Decimal('0.15')), ('ice cream', Decimal('3.49')), ('strawberries', Decimal('2.00')), ('snickers bar', Decimal('0.70')), ('mars bar', Decimal('0.65'))] return ProductStore(products)
def test_item_after_init_from_filepath(self): '''An item's price can be retrieved from a ProductStore that's been created from a csv file.''' csv_filepath = os.path.abspath('test_products.csv') product_store = ProductStore.init_from_filepath(csv_filepath) self.assertEqual(product_store.get_product_price('apple'), Decimal('0.15'))
def _create_product_store(self): """ Helper method to create populated ProductStore. """ products = [ ("pasta", Decimal("1.50")), ("twix", Decimal("0.80")), ("blueberries", Decimal("2.00")), ("fish", Decimal("3.20")), ] return ProductStore(products)
def _create_product_store(self): '''Helper method to create populated ProductStore.''' products = [{ "name": "apple", "price": 0.15 }, { "name": "ice cream", "price": 3.49 }, { "name": "dairy milk", "price": 2.00 }, { "name": "kitkat", "price": 0.70 }] return ProductStore(products)
def test_init_from_filepath(self): '''ProductStore object can be created from json file.''' json_file = os.path.abspath('test_products.json') product_store = ProductStore.load_products(json_file) self.assertEqual(len(product_store.items), 4)
def test_init_from_filepath(self): '''ProductStore object can be created from csv file.''' csv_filepath = os.path.abspath('test_products.csv') product_store = ProductStore.init_from_filepath(csv_filepath) self.assertEqual(len(product_store.items), 5)
import os import unittest from decimal import Decimal from cart import Cart, CartItem from product import ProductStore from offers import BuyGetOffer, PercentageDiscountOffer productDetail=ProductStore('test_products.csv') class CartTest(unittest.TestCase): def test_add_one_items(self): cart = Cart() cart.add('Biscuits',2) self.assertEqual(cart.get_total(), 2.4) def test_add_two_items(self): cart = Cart() cart.add('Biscuits',2) cart.add('Baked Beans',3) self.assertEqual(cart.get_total(), 5.37) def test_add_two_same_items(self): cart = Cart() cart.add('Biscuits',2) cart.add('Biscuits',2) self.assertEqual(cart.get_total(), 4.8) def test_add_items_no_quantity(self): #if no quanity is given default value is 1 cart = Cart()