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, **kwargs): Inventory.__init__( self, **kwargs) # Initializes common instance attributes from the # parent class self.brand = kwargs["brand"] self.voltage = kwargs["voltage"]
def __init__(self, **kwargs): Inventory.__init__( self, **kwargs) # Initializes common instance attributes from the # parent class self.material = kwargs["material"] self.size = kwargs["size"]
def test_create_inventory_item(cls): """ Create an inventory object and make sure it initializes properly """ inventory = Inventory('CORN', 'The plant corn', 30, 0) item_dict = inventory.return_as_dictionary() assert item_dict['productCode'] == 'CORN' assert item_dict['description'] == 'The plant corn' assert item_dict['marketPrice'] == 30 assert item_dict['rentalPrice'] == 0
def __init__(self, product_code, description, market_price, rental_price, material, size): Inventory.__init__(self, product_code, description, market_price, rental_price) # Creates common # instance variables from the parent class self.material = material self.size = size
def __init__(self, product_code, description, market_price, rental_price, material, size): """ inherited """ Inventory.__init__(self, product_code, description, market_price, rental_price) self.material = material self.size = size
def test_Inventory(self): inventory = Inventory("PC", "Desc", "MP", "RP") self.assertDictEqual(inventory.return_as_dictionary(), { 'product_code': "PC", 'description': "Desc", 'market_price': "MP", 'rental_price': "RP" } )
def test_return_as_dictionary(self): product = Inventory(product_code="8A", description="Some thingy", market_price=1.50, rental_price=0.50) test_dict = {} test_dict["product_code"] = "8A" test_dict["description"] = "Some thingy" test_dict["market_price"] = 1.50 test_dict["rental_price"] = 0.50 self.assertDictEqual(test_dict, product.return_as_dictionary())
def test_inventory(self): """ Test creation of an Inventory item """ inventory = Inventory(1, 'Dummy Description', 100, 10) self.assertEqual( { 'product_code': 1, 'description': 'Dummy Description', 'market_price': 100, 'rental_price': 10 }, inventory.return_as_dictionary())
def test_inventory_return_as_dictionary(self): # Given args = { "product_code": 42, "description": "The test item", "market_price": 12.34, "rental_price": 5.67, } # When self.inventory = Inventory(**args) # Then self.assertEqual(args, self.inventory.return_as_dictionary())
class InventoryTest(TestCase): def test_inventory_init(self): # Given args = { "product_code": 42, "description": "The test item", "market_price": 12.34, "rental_price": 5.67, } # When self.inventory = Inventory(**args) # Then self.assertEqual(42, self.inventory.product_code) self.assertEqual("The test item", self.inventory.description) self.assertEqual(12.34, self.inventory.market_price) self.assertEqual(5.67, self.inventory.rental_price) def test_inventory_return_as_dictionary(self): # Given args = { "product_code": 42, "description": "The test item", "market_price": 12.34, "rental_price": 5.67, } # When self.inventory = Inventory(**args) # Then self.assertEqual(args, self.inventory.return_as_dictionary())
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 return_as_dictionary(self): ''' Output furniture as a dictionary ''' output = Inventory.return_as_dictionary(self) output['material'] = self.material output['size'] = self.size return output
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_init(self): product = Inventory(product_code="8A", description="Some thingy", market_price=1.50, rental_price=0.50) 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)
class InventoryTests(TestCase): def setUp(self): self.widget = Inventory('GEN234', 'Generic Widget', 400.25, 12.45) def test_create_furniture(self): self.assertEqual(self.widget.product_code, 'GEN234') self.assertEqual(self.widget.description, 'Generic Widget') self.assertEqual(self.widget.rental_price, 12.45) self.assertEqual(self.widget.market_price, 400.25) def test_return_as_dict(self): self.assertEqual( self.widget.return_as_dictionary().get('product_code'), 'GEN234') self.assertEqual(self.widget.return_as_dictionary().get('description'), 'Generic Widget') self.assertEqual( self.widget.return_as_dictionary().get('market_price'), 400.25) self.assertEqual( self.widget.return_as_dictionary().get('rental_price'), 12.45)
def test_inventory(self): """ assert equal """ inventory_test = Inventory('111', 'description', 'marketprice', 'rentalprice').return_as_dictionary() self.assertEqual( inventory_test, { 'product_code': '111', 'description': 'description', 'market_price': 'marketprice', 'rental_price': 'rentalprice' })
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 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 return_as_dictionary(self): output = Inventory.return_as_dictionary(self) output['brand'] = self.brand output['voltage'] = self.voltage return output
def test_return_as_dict_inventory(self): chair = Inventory(1, "lawn_chair", 5, 2) my_dict = {"product_code": 1, "description": "lawn_chair", "market_price": 5, "rental_price": 2} self.assertEqual(my_dict, chair.return_as_dictionary())
def test_init_inventory(self): chair = Inventory(1, "lawn_chair", 5, 2) self.assertEqual(1, chair.product_code) self.assertEqual("lawn_chair", chair.description) self.assertEqual(5, chair.market_price) self.assertEqual(2, chair.rental_price)
def setUp(self): self.widget = Inventory('GEN234', 'Generic Widget', 400.25, 12.45)