def test_electric_appliances_class(self): """Test the ElectricAppliances instantiation and return_as_directory() method""" expected = { 'item_code': 'OVEN', 'description': 'A great double oven', 'market_price': '599.99', 'rental_price': '40.00', 'brand': 'GT', 'voltage': '240V' } item_attributes = { 'item_code': 'OVEN', 'description': 'A great double oven', 'market_price': '599.99', 'rental_price': '40.00', 'brand': 'GT', 'voltage': '240V' } self.item = ElectricAppliances(**item_attributes) self.assertIsInstance(self.item, Inventory, ElectricAppliances) self.assertEqual(expected, self.item.return_as_dictionary())
def test_electric_appliances(self): electric = ElectricAppliances(10, "thing", 24, 1000, "Mine", 60) out_dict = {"product_code": 10, "description": "thing", "market_price": 24, "rental_price": 1000, "brand": "Mine", "voltage": 60} self.assertEqual(out_dict, electric.return_as_dictionary())
def test_electric(self): """Tests the creation of an instance for electric object""" test_dict = { 'product_code': 6789, 'description': 'Horse', 'market_price': 50, 'rental_price': 10, 'brand': 'Sony', 'voltage': 28 } test_elec = ElectricAppliances(6789, 'Horse', 50, 10, 'Sony', 28) self.assertEqual(test_dict, test_elec.return_as_dictionary())
def test_electric_appliances_class(self): self.test_item = ElectricAppliances("123", "RiceCooker", "29.99", "5.99", "GE", "220") self.test_dict = self.test_item.return_as_dictionary() self.assertDictEqual( self.test_dict, { "product_code": "123", "description": "RiceCooker", "market_price": "29.99", "rental_price": "5.99", "brand": "GE", "voltage": "220" })
def test_integration(self): """Tests the integration of main with other modules""" new_item = Inventory(1, 'horse', 50, 10) new_electric = ElectricAppliances(2, 'horse', 50, 10, 'Sony', 5) new_furniture = Furniture(3, 'horse', 50, 10, 'leather', 'huge') new_item_specs = new_item.return_as_dictionary() new_electric_specs = new_electric.return_as_dictionary() new_furniture_specs = new_furniture.return_as_dictionary() self.assertEqual(1, new_item_specs['product_code']) self.assertEqual(2, new_electric_specs['product_code']) self.assertEqual(3, new_furniture_specs['product_code'])
def test_electtric_appliances(self): """Test that the electric appliances class returns the correct dict.""" ea = ElectricAppliances(EA_CDE, EA_DSC, EA_MKT_PRC, EA_RNT_PRC, EA_BRD, EA_VLT) self.assertEqual( { 'product_code': EA_CDE, 'description': EA_DSC, 'market_price': EA_MKT_PRC, 'rental_price': EA_RNT_PRC, 'brand': EA_BRD, 'voltage': EA_VLT }, ea.return_as_data_struct())
def test_electric_appliances_initialization(self): """ Tests for successful, accurate initalization of ElectricAppliances. """ new_product = ElectricAppliances(3, 'Blender', 200, 20, 'Krups', 110) new_product_dict = new_product.return_as_dictionary() self.assertEqual(3, new_product_dict['product_code']) self.assertEqual('Blender', new_product_dict['description']) self.assertEqual(200, new_product_dict['market_price']) self.assertEqual(20, new_product_dict['rental_price']) self.assertEqual('Krups', new_product_dict['brand']) self.assertEqual(110, new_product_dict['voltage'])
def test_electic_appliance_class(self): """Test of the ElectricAppliance class.""" appliance_test = ElectricAppliances("Maytag", 240, "EA-1", "Washing Machine", 650, 75) appliance_test_dict = { "brand": "Maytag", "voltage": 240, "product_code": "EA-1", "description": "Washing Machine", "market_price": 650, "rental_price": 75 } self.assertDictEqual(vars(appliance_test), appliance_test_dict) self.assertDictEqual(appliance_test.return_as_dictionary(), appliance_test_dict)
def add_new_item(): """ add a new item :return: """ 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 setUp(self): """Sets up the initial paramaeters""" self.product_code = '26' self.description = 'Oven' self.market_price = '$50' self.rental_price = '$20' self.brand = 'Bosch' self.voltage = '120V' self.test_appliance = ElectricAppliances(self.product_code, self.description, self.market_price, self.rental_price, self.brand, self.voltage) self.expected_appliance_dict = { 'product_code': self.product_code, 'description': self.description, 'market_price': self.market_price, 'rental_price': self.rental_price, 'brand': self.brand, 'voltage': self.voltage }
class ElectricApplianceTests(TestCase): """Tests the Electrical Appliance Subclass of Inventory""" def setUp(self): """Sets up the initial paramaeters""" self.product_code = '26' self.description = 'Oven' self.market_price = '$50' self.rental_price = '$20' self.brand = 'Bosch' self.voltage = '120V' self.test_appliance = ElectricAppliances(self.product_code, self.description, self.market_price, self.rental_price, self.brand, self.voltage) self.expected_appliance_dict = { 'product_code': self.product_code, 'description': self.description, 'market_price': self.market_price, 'rental_price': self.rental_price, 'brand': self.brand, 'voltage': self.voltage } def test_appliance_creation(self): """Tests creation of appliance subclass""" assert self.test_appliance.product_code == self.product_code assert self.test_appliance.description == self.description assert self.test_appliance.market_price == self.market_price assert self.test_appliance.rental_price == self.rental_price assert self.test_appliance.brand == self.brand assert self.test_appliance.voltage == self.voltage def test_appliance_dict(self): """Tests successful creation of the dictionary""" test_app_dict = self.test_appliance.return_as_dictionary() assert test_app_dict == self.expected_appliance_dict
def test_add_new_item(self): """Test that new items are properly categorized and constructed, ... ...with market prices and FULL_INVENTORY mocked.""" mkt_prc.get_latest_price = Mock(return_value=543) FULL_INVENTORY = Mock(return_value='dummy') with patch('builtins.input', side_effect=[ FUR_CDE, FUR_DSC, FUR_RNT_PRC, 'Y', FUR_MAT, FUR_SZ ]): self.assertEqual( Furniture(FUR_CDE, FUR_DSC, 543, FUR_RNT_PRC, FUR_MAT, FUR_SZ), add_new_item()) with patch('builtins.input', side_effect=[ EA_CDE, EA_DSC, EA_RNT_PRC, 'N', 'Y', EA_BRD, EA_VLT ]): self.assertEqual( ElectricAppliances(EA_CDE, EA_DSC, 543, EA_RNT_PRC, EA_BRD, EA_VLT), add_new_item()) with patch('builtins.input', side_effect=[INV_CDE, INV_DSC, INV_RNT_PRC, 'N', 'N']): self.assertEqual(Inventory(INV_CDE, INV_DSC, 543, INV_RNT_PRC), add_new_item())