def test_add_new_item_furniture(self): text_trap = io.StringIO() sys.stdout = text_trap 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" item_dict["item_material"] = "a" item_dict["size"] = "S" item_dict["style"] = "furniture" user_input = ["1", "a", "1.0", "y", "a", "S"] f_inventory = {} f = Furniture(**item_dict) f_inventory = {} with patch('builtins.input', side_effect=user_input): f_inventory = add_new_item(f_inventory) new_dict = f_inventory["1"] f = Furniture(**item_dict) new_dict1 = f.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["material"], new_dict1["material"]) self.assertEqual(new_dict["size"], new_dict1["size"]) sys.stdout = sys.__stdout__
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_return_as_dictionary(self): """ Tests the return as dictionary method of the Furniture class. Ensures the length of returned dictionary matches desired length. :return: None """ # Create an instance of the Furniture Class furniture = Furniture("1", "2", "3", "4", "5", "6") # Obtain dictionary through return_as_dictionary # method for comparison test_dic = furniture.return_as_dictionary() # Verify return_as_dictionary function populates # Each item, and are properly instantiated self.assertEqual(6, 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']) self.assertEqual('5', test_dic['material']) self.assertEqual('6', test_dic['size'])
def test_check_for_big_screen(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 item_dict["item_material"] = "a" item_dict["size"] = "S" f = Furniture(**item_dict) self.assertEqual(f.check_for_big_screen(), False) f.size = "XL" self.assertEqual(f.check_for_big_screen(), True)
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 item_dict["item_material"] = "a" item_dict["size"] = "S" f = Furniture(**item_dict) new_dict = f.return_as_dictionary() self.assertEqual(f.product_code, new_dict["product_code"]) self.assertEqual(f.description, new_dict["description"]) self.assertEqual(f.rental_price, new_dict["rental_price"]) self.assertEqual(f.material, new_dict["material"]) self.assertEqual(f.size, new_dict["size"])
class FurnitureTests(TestCase): """ Tests for the Furniture class """ def setUp(self): """ Sets up tests for Furniture """ self.item = Furniture('11', 'sofa', '4', '5', 'suede', 'xl') def test_init(self): """ Test ElectricAppliances.__init__() """ self.assertEqual(self.item.material, 'suede') self.assertEqual(self.item.size, 'xl') self.assertEqual(self.item.description, 'sofa') def test_dict(self): """ Test Furniture.return_as_dictionary() """ self.assertEqual( self.item.return_as_dictionary(), { 'product_code': '11', 'description': 'sofa', 'market_price': '4', 'rental_price': '5', 'material': 'suede', 'size': 'xl' })
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
def test_init(self): """ Test that a proper Furniture object is returned """ item = Furniture( 1, "F1", "5000", "6000", material="Leather", size="L") self.assertEqual("Leather", item.material) self.assertEqual("L", item.size) self.assertEqual("F1", item.description)
def test_dict(self): """ Test that a proper Furniture dict is returned """ item = Furniture( 1, "F1", "5000", "6000", material="Leather", size="L") output_dict = item.return_as_dictionary() self.assertEqual( { 'product_code': 1, 'description': 'F1', 'market_price': '5000', 'rental_price': '6000', 'material': 'Leather', 'size': 'L' }, output_dict)
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 item_dict["item_material"] = "b" item_dict["size"] = "D" f = Furniture(**item_dict) self.assertEqual(f.product_code, 2) self.assertEqual(f.description, "b") self.assertEqual(f.rental_price, 2.0) self.assertEqual(f.market_price, 2.0) self.assertEqual(f.material, "b") self.assertEqual(f.size, "D")
def test_furniture(self): elect_app1 = { 'productCode': '001', 'description': 'elect_1', 'marketPrice': '$25', 'rentalPrice': '$15', 'material': 'material1', 'size': 'size1' } self.assertEqual( elect_app1, Furniture('material1', 'size1', '001', 'elect_1', '$25', '$15').return_as_dictionary())
def setUp(self): self.furniture = Furniture(product_code=1, description='test', market_price=99.99, rental_price=9.99, material='Leather', size='S') self.expected_furniture_dict = { 'product_code': 1, 'description': 'test', 'market_price': 99.99, 'rental_price': 9.99, 'material': 'Leather', 'size': 'S' }
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 Furniture Class furniture = Furniture("1", "2", "3", "4", "5", "6") # Test to verify data has been passed through the # initializer self.assertIsNotNone(furniture.product_code) self.assertIsNotNone(furniture.description) self.assertIsNotNone(furniture.market_price) self.assertIsNotNone(furniture.rental_price) self.assertIsNotNone(furniture.material) self.assertIsNotNone(furniture.size)
def setUp(self): """ Sets up tests for Furniture """ self.item = Furniture('11', 'sofa', '4', '5', 'suede', 'xl')