def __init__(self, **kwargs): Inventory.__init__( self, ** kwargs) # Creates common instance variables from the parent class self.brand = kwargs["brand"] self.voltage = kwargs["voltage"]
def __init__(self, **kwargs): Inventory.__init__( self, ** kwargs) # Creates common instance variables from the parent class self.material = kwargs["item_material"] self.size = kwargs["size"]
def __init__(self, product_code, description, market_price, rental_price, brand, voltage): # Creates common instance variables from the parent class Inventory.__init__(self, product_code, description, market_price, rental_price) self.brand = brand self.voltage = voltage
def __init__(self, product_code, description, market_price, rental_price, material, size): # Creates common instance variables from the parent class Inventory.__init__(self, product_code, description, market_price, rental_price) self.material = material self.size = size
def test_check_market_price(self): item_dict = {} item_dict["item_code"] = 1 item_dict["item_description"] = "a" item_dict["item_rental_price"] = 1.0 item_dict["item_price"] = 1.0 i = Inventory(**item_dict) self.assertEqual(i.check_market_price(), False) i.market_price = get_latest_price() self.assertEqual(i.check_market_price(), True)
def setUp(self): self.inventory = Inventory(product_code=1, description='test', market_price=99.99, rental_price=9.99) self.expected_inventory_dict = { 'product_code': 1, 'description': 'test', 'market_price': 99.99, 'rental_price': 9.99 }
def test_return_as_dictionary(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i = Inventory(**item_dict) new_dict = i.return_as_dictionary() self.assertEqual(i.product_code, new_dict["product_code"]) self.assertEqual(i.description, new_dict["description"]) self.assertEqual(i.rental_price, new_dict["rental_price"])
def test_dict(self): """ Test that a proper Inventory dict is returned """ item = Inventory(1, "Item1", "200", "400") output_dict = item.return_as_dictionary() self.assertEqual( { 'product_code': 1, 'description': 'Item1', 'market_price': '200', 'rental_price': '400' }, output_dict)
class Test_InventoryClass(TestCase): def test_init(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i = Inventory(**item_dict) self.assertEqual(i.product_code, 2) self.assertEqual(i.description, "b") self.assertEqual(i.rental_price, 2.0) self.assertEqual(i.market_price, 2.0) def test_return_as_dictionary(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i = Inventory(**item_dict) new_dict = i.return_as_dictionary() self.assertEqual(i.product_code, new_dict["product_code"]) self.assertEqual(i.description, new_dict["description"]) self.assertEqual(i.rental_price, new_dict["rental_price"]) def test_check_market_price(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i = Inventory(**item_dict) self.assertEqual(i.check_market_price(), False) i.market_price = get_latest_price() self.assertEqual(i.check_market_price(), True)
def add_new_item(): ''' Add new item to the inventory ''' item_code = input("Enter item code: ") item_description = input("Enter item description: ") item_rental_price = input("Enter item rental price: ") # Get price from the market prices module item_price = get_latest_price(item_code) is_furniture = input("Is this item a piece of furniture? (Y/N): ") if is_furniture.lower() == "y": item_material = input("Enter item material: ") item_size = input("Enter item size (S,M,L,XL): ") new_item = Furniture(item_code, item_description, item_price, item_rental_price, item_material, item_size) else: is_electric_appliance = input( "Is this item an electric appliance? (Y/N): ") if is_electric_appliance.lower() == "y": item_brand = input("Enter item brand: ") item_voltage = input("Enter item voltage: ") new_item = ElectricAppliances(item_code, item_description, item_price, item_rental_price, item_brand, item_voltage) else: new_item = Inventory(item_code, item_description, item_price, item_rental_price) FULL_INVENTORY[item_code] = new_item.return_as_dictionary() print("New inventory item added")
def test_init(self): """ Test that a proper Inventory object is returned """ item = Inventory(1, "Item1", "200", "400") self.assertEqual(1, item.product_code) self.assertEqual("Item1", item.description) self.assertEqual("200", item.market_price) self.assertEqual("400", item.rental_price)
def test_add_new_item_inventory(self): text_trap = io.StringIO() sys.stdout = text_trap user_input = ["3", "c", "3.0", "n", "n"] f_inventory = {} with patch('builtins.input', side_effect=user_input): f_inventory = add_new_item(f_inventory) new_dict = f_inventory["3"] item_dict = {} item_dict["item_code"] = "3" item_dict["item_description"] = "c" item_dict["item_rental_price"] = "3.0" item_dict["item_price"] = get_latest_price() i = Inventory(**item_dict) new_dict1 = i.return_as_dictionary() self.assertEqual(new_dict["product_code"], new_dict1["product_code"]) self.assertEqual(new_dict["description"], new_dict1["description"]) self.assertEqual(new_dict["rental_price"], new_dict1["rental_price"]) self.assertEqual(new_dict["market_price"], new_dict1["market_price"]) sys.stdout = sys.__stdout__
def test_init(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i = Inventory(**item_dict) self.assertEqual(i.product_code, 2) self.assertEqual(i.description, "b") self.assertEqual(i.rental_price, 2.0) self.assertEqual(i.market_price, 2.0)
def test_inventory(self): elect_app1 = { 'productCode': '001', 'description': 'elect_1', 'marketPrice': '$25', 'rentalPrice': '$15' } self.assertEqual( elect_app1, Inventory('001', 'elect_1', '$25', '$15').return_as_dictionary())
def test_return_item_info(self): item_dict = {} item_dict["item_code"] = 2 item_dict["item_description"] = "b" item_dict["item_rental_price"] = 2.0 item_dict["item_price"] = 2.0 i1 = Inventory(**item_dict) item_dict1 = {} item_dict1["item_code"] = 2 item_dict1["item_description"] = "b" item_dict1["item_rental_price"] = 2.0 item_dict1["item_price"] = 2.0 i2 = Inventory(**item_dict1) f_inventory = {} f_inventory["1"] = i1.return_as_dictionary() f_inventory["2"] = i2.return_as_dictionary() self.assertEqual( return_item_info(f_inventory, "2"), "product_code:1\ndescription:a\nmarket_price:1.0\nrental_price:1.0\n" ) self.assertEqual( return_item_info(f_inventory, "2"), "product_code:2\ndescription:b\nmarket_price:2.0\nrental_price:2.0\n" ) self.assertEqual( return_item_info(f_inventory, "z"), "Item not found in inventory")
def test_return_as_dictionary(self): """ Tests the return as dictionary method of the inventory class. Ensures the length of returned dictionary matches desired length. :return: None """ # Create an instance of the Inventory Class inventory = Inventory("1", "2", "3", "4") # Obtain dictionary through return_as_dictionary # method for comparison test_dic = inventory.return_as_dictionary() # Verify return_as_dictionary function populates # Each item, and are properly instantiated self.assertEqual(4, len(test_dic)) self.assertEqual('1', test_dic['product_code']) self.assertEqual('2', test_dic['description']) self.assertEqual('3', test_dic['market_price']) self.assertEqual('4', test_dic['rental_price'])
def test_initializer(self): """ Tests the initializer of the Inventory class. Verifies classes attributes are filled when class is instantiated. :return: None """ # Create an instance of the Inventory Class inventory = Inventory("1", "2", "3", "4") # Test to verify data has been passed through the # initializer self.assertIsNotNone(inventory.product_code) self.assertIsNotNone(inventory.description) self.assertIsNotNone(inventory.market_price) self.assertIsNotNone(inventory.rental_price)
def add_new_item(f_inventory): """ Function to add an additional item to Inventory """ # Get price from the market prices module item_price = get_price() item_dict = input_item_info() item_dict["item_price"] = item_price if item_dict.get("style") == "furniture": new_item = Furniture(**item_dict) elif item_dict.get("style") == "electric": new_item = ElectricAppliances(**item_dict) else: new_item = Inventory(**item_dict) f_inventory[item_dict["item_code"]] = new_item.return_as_dictionary() print("New inventory item added") return f_inventory
class InventoryClassTest(TestCase): """ This class tests the InventoryClass module """ def setUp(self): self.inventory = Inventory(product_code=1, description='test', market_price=99.99, rental_price=9.99) self.expected_inventory_dict = { 'product_code': 1, 'description': 'test', 'market_price': 99.99, 'rental_price': 9.99 } def test_inventory_init(self): self.assertEqual(self.inventory.__dict__, self.expected_inventory_dict) self.assertIsInstance(self.inventory, Inventory) def test_return_as_dictionary(self): """ Verify dictionary returned matches expected """ self.assertDictEqual(self.inventory.return_as_dictionary(), self.expected_inventory_dict)
def __init__(self, product_code, description, market_price, rental_price, brand, voltage): Inventory.__init__(self, product_code, description, market_price, rental_price) self.brand = brand self.voltage = voltage
def setUp(self): self.inventory_item1 = \ Inventory(product_code=1, description='test', market_price=99.99, rental_price=9.99) self.get_latest_price = \ get_latest_price(item_code=self.inventory_item1.product_code)