def test_furniture_return_as_dict(self): item = Furniture(**self.data) result = item.return_as_dictionary() self.assertEqual(len(self.data), len(result)) for name, value in self.data.items(): self.assertEqual(value, result[name])
def add_new_item(): """ Adds a new item to the inventory of all items based on the object type. """ 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_create_furniture_item(cls): """ Create a furniture object and make sure it initializes correctly """ furniture = Furniture('SOFA', 'A place to sit', 300, 50, 'Cloth', '2 Meters') item_dict = furniture.return_as_dictionary() assert item_dict['productCode'] == 'SOFA' assert item_dict['description'] == 'A place to sit' assert item_dict['marketPrice'] == 300 assert item_dict['rentalPrice'] == 50 assert item_dict['Material'] == 'Cloth' assert item_dict['Size'] == '2 Meters'
def test_furniture(self): furniture = Furniture("PC", "Desc", "MP", "RP", "M", "S") self.assertDictEqual(furniture.return_as_dictionary(), { 'product_code': "PC", 'description': "Desc", 'market_price': "MP", 'rental_price': "RP", 'material': "M", 'size': "S" } )
def test_furniture(self): """ Test creation of a Furniture item """ furniture = Furniture(3, 'Dummy Description', 100, 10, 'Upholstery', 'L') self.assertEqual( { 'product_code': 3, 'description': 'Dummy Description', 'market_price': 100, 'rental_price': 10, 'material': 'Upholstery', 'size': 'L' }, furniture.return_as_dictionary())
def test_return_as_dictionary(self): product = Furniture(product_code="8A", description="Some thingy", market_price=1.50, rental_price=0.50, material="carbon fiber", size="humongous") test_dict = {} test_dict["product_code"] = "8A" test_dict["description"] = "Some thingy" test_dict["market_price"] = 1.50 test_dict["rental_price"] = 0.50 test_dict["material"] = "carbon fiber" test_dict["size"] = "humongous" self.assertDictEqual(test_dict, product.return_as_dictionary())
def test_furniture_init(self): # Given args = { "product_code": "Test5678", "description": "Test Sofa", "market_price": 123.45, "rental_price": 10.20, "material": "Flubber", "size": "Triple Single", } # When self.furniture = Furniture(**args) # Then self.assertEqual(args, self.furniture.return_as_dictionary())
def test_init_furniture(self): table = Furniture(2, "poker_table", 10, 4, "plastic", "small") self.assertEqual(2, table.product_code) self.assertEqual("poker_table", table.description) self.assertEqual(10, table.market_price) self.assertEqual(4, table.rental_price) self.assertEqual("plastic", table.material) self.assertEqual("small", table.size)
def test_module(self): """ initiate item's attributes and test """ inventory_item = Inventory(1, 'stapler', 10, 5) furniture_item = Furniture(2, 'sofa', 20, 10, 'wood', 'king') electric_item = Electric(3, 'boiler', 30, 15, '', 8) inventory_item_info = inventory_item.return_as_dictionary() furniture_item_info = furniture_item.return_as_dictionary() electric_item_info = electric_item.return_as_dictionary() self.assertEqual(1, inventory_item_info['product_code']) self.assertEqual('stapler', inventory_item_info['description']) self.assertEqual(2, furniture_item_info['product_code']) self.assertEqual('sofa', furniture_item_info['description']) self.assertEqual(3, electric_item_info['product_code']) self.assertEqual('boiler', electric_item_info['description'])
def test_furniture_create(self): item = Furniture( self.data["product_code"], self.data["description"], self.data["market_price"], self.data["rental_price"], self.data["material"], self.data["size"]) self.assertEqual(self.data["product_code"], item.product_code) self.assertEqual(self.data["description"], item.description) self.assertEqual(self.data["market_price"], item.market_price) self.assertEqual(self.data["rental_price"], item.rental_price) self.assertEqual(self.data["material"], item.material) self.assertEqual(self.data["size"], item.size)
def setUp(self): self.tv_code = 24332 self.table_code = 89773 self.lamp_code = 7346 self.tv = ElectricAppliances(self.tv_code, 'Samsung TV', 1200.00, 125.00, 'Samsung', 120) self.table = Furniture(self.table_code, 'Coffee Table', 300.00, 125.00, 'Glass', 'L') self.lamp = ElectricAppliances(self.lamp_code, 'Bed side lamp', 20.00, 23.00, 'Target', 9)
class FurnitureTests(TestCase): def setUp(self): self.new_chair = Furniture(1321, 'Chair', 1203.05, 35.00, 'wood', 'XL') def test_create_furniture(self): self.assertEqual(self.new_chair.size, 'XL') self.assertEqual(self.new_chair.material, 'wood') self.assertEqual(self.new_chair.rental_price, 35.00) self.assertEqual(self.new_chair.market_price, 1203.05) self.assertEqual(self.new_chair.description, 'Chair') self.assertEqual(self.new_chair.product_code, 1321) def test_return_as_dict(self): self.assertEqual( self.new_chair.return_as_dictionary().get('product_code'), 1321) self.assertEqual( self.new_chair.return_as_dictionary().get('description'), 'Chair') self.assertEqual( self.new_chair.return_as_dictionary().get('market_price'), 1203.05) self.assertEqual( self.new_chair.return_as_dictionary().get('rental_price'), 35.00) self.assertEqual(self.new_chair.return_as_dictionary().get('material'), 'wood') self.assertEqual(self.new_chair.return_as_dictionary().get('size'), 'XL')
def test_init(self): product = Furniture(product_code="8A", description="Some thingy", market_price=1.50, rental_price=0.50, material="carbon fiber", size="humongous") self.assertEqual("8A", product.product_code) self.assertEqual("Some thingy", product.description) self.assertEqual(1.50, product.market_price) self.assertEqual(0.50, product.rental_price) self.assertEqual("carbon fiber", product.material) self.assertEqual("humongous", product.size)
def test_module(self): rug = Inventory(7, "oriental_rug", 30, 5) rug_info = rug.return_as_dictionary() sofa = Furniture(5, "brown_sofa", 100, 20, "leather", "large") sofa_info = sofa.return_as_dictionary() tv = ElectricAppliances(6, "4k_tv", 2000, 50, "Panasonic", 220) tv_info = tv.return_as_dictionary() price = get_latest_price(8) self.assertEqual(7, rug.product_code) self.assertEqual("oriental_rug", rug_info["description"]) self.assertEqual("brown_sofa", sofa.description) self.assertEqual(100, sofa_info["market_price"]) self.assertEqual(2000, tv.market_price) self.assertEqual(50, tv_info["rental_price"]) self.assertEqual(24, get_latest_price(1))
def test_furniture(self): """ assert equal """ furniture_test = Furniture('222', 'description', 'marketprice', 'rentalprice', 'material', 'size').return_as_dictionary() self.assertEqual( furniture_test, { 'product_code': '222', 'description': 'description', 'market_price': 'marketprice', 'rental_price': 'rentalprice', 'material': 'material', 'size': 'size' })
def add_new_item(): """ Collect information to add an inventory item and create it. """ # global fullInventory # uhm - let's avoid globals, ok? item_code, item_description, item_rental_price, item_price = collect_product_info( ) if get_is_furniture().lower() == "y": item_material, item_size = collect_furniture_info() new_item = Furniture(product_code=item_code, description=item_description, rental_price=item_rental_price, market_price=item_price, material=item_material, size=item_size) elif get_is_electric_appliance().lower() == "y": item_brand, item_voltage = collect_electric_appliance_info() new_item = ElectricAppliance(product_code=item_code, description=item_description, rental_price=item_rental_price, market_price=item_price, brand=item_brand, voltage=item_voltage) else: new_item = Inventory(product_code=item_code, description=item_description, rental_price=item_rental_price, market_price=item_price) FULL_INVENTORY[item_code] = new_item.return_as_dictionary() print("New inventory item added") return FULL_INVENTORY[item_code]
def test_add_new_furniture(self): """ assert equal """ furniture_record = list( Furniture('300', 'chair', '40', 'Y', 'wood', 'L').return_as_dictionary().values()) with patch('builtins.input', side_effect=furniture_record): test_furniture = add_new_item() self.assertEqual( test_furniture['300'], { 'product_code': '300', 'description': 'chair', 'market_price': 24, 'rental_price': '40', 'material': 'wood', 'size': 'L' })
def test_furniture_sort_key(self): item = Furniture(**self.data) result = Furniture.sort_key(item) self.assertEqual(result, (item.description, item.product_code))
def test_return_as_dict_furniture(self): table = Furniture(2, "poker_table", 10, 4, "plastic", "small") my_dict = {"product_code": 2, "description": "poker_table", "market_price": 10, "rental_price": 4, "material": "plastic", "size": "small"} self.assertEqual(my_dict, table.return_as_dictionary())
def setUp(self): self.new_chair = Furniture(1321, 'Chair', 1203.05, 35.00, 'wood', 'XL')