def test_inventory(self): inventory = Inventory(10, "thing", 24, 1000) out_dict = {"product_code": 10, "description": "thing", "market_price": 24, "rental_price": 1000} self.assertEqual(out_dict, inventory.return_as_dictionary())
class InventoryTest(TestCase): """ Test the inventory class """ def setUp(self): """ Create an inventory object""" self.product_code = '101' self.description = 'lamp' self.market_price = '$10' self.rental_price = '$7' self.example_inventory = Inventory(self.product_code, self.description, self.market_price, self.rental_price) self.correct_dict = { 'product_code': self.product_code, 'description': self.description, 'market_price': self.market_price, 'rental_price': self.rental_price } def test_inventory(self): """ Verify that the attributes have been appropriately assigned""" assert self.example_inventory.product_code == self.product_code assert self.example_inventory.description == self.description assert self.example_inventory.market_price == self.market_price assert self.example_inventory.rental_price == self.rental_price def test_return_as_dictionary(self): """ Verify that object is correctly defined in a dictionary """ dict_return = self.example_inventory.return_as_dictionary() assert dict_return == self.correct_dict
def return_as_dictionary(self): """Output dictionary""" output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
class InventoryTests(TestCase): """Tests for the Inventory object""" def setUp(self): """Gives set up parameters""" self.product_code = '26' self.description = 'couch' self.market_price = "$50" self.rental_price = "$20" self.test_inventory = Inventory(self.product_code, self.description, self.market_price, self.rental_price) self.expected_dict = { 'product_code': self.product_code, 'description': self.description, 'market_price': self.market_price, 'rental_price': self.rental_price } def test_inventory_creation(self): """Tests successful creation of inventory object""" assert self.test_inventory.product_code == self.product_code assert self.test_inventory.description == self.description assert self.test_inventory.market_price == self.market_price assert self.test_inventory.rental_price == self.rental_price def test_dict_creation(self): """Tests dict creation and accuracy""" test_out_dict = self.test_inventory.return_as_dictionary() assert test_out_dict == self.expected_dict
def return_as_dictionary(self): '''Returns the furniture inventory as a dictionary''' output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Returns info on item as a dictionary""" output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """method docstring""" output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """method docstring""" output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Function to store furniture as a data dictionary""" output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Function to return Inventory as dictionary""" output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """Returns a dictionary of the furniture information""" output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): '''Returns the electrical appliances inventory as a dictionary''' output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """Returns info on item as a dictionary""" output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Returns a dictionary of the appliance information""" output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def test_main_integration(self): """Test all functions with main as a starting point""" price = market_prices.get_latest_price(0) #Adding non categorized inventory item with main input1 = ['1', 'shoe', '1', 'n', 'n'] item1 = Inventory('1', 'shoe', price, '1') with patch('builtins.input', side_effect=input1): add_new_item() #Adding furniture item with main input2 = ['2', 'chair', '2', 'y', 'wood', 'S'] item2 = Furniture('2', 'chair', price, '2', 'wood', 'S') with patch('builtins.input', side_effect=input2): add_new_item() #Adding electric appliance with main input3 = ['3', 'stove', '3', 'n', 'y', 'LG', '100'] item3 = ElectricAppliances('3', 'stove', price, '3', 'LG', '100') with patch('builtins.input', side_effect=input3): add_new_item() actual_inventory = return_inventory() expected_inventory = { '1': item1.return_as_dictionary(), '2': item2.return_as_dictionary(), '3': item3.return_as_dictionary()} self.assertEqual(actual_inventory, expected_inventory)
def return_as_dictionary(self): """Function returns Furniture inventory instance properties as a dictionary to be included in the inventory database.""" item = Inventory.return_as_dictionary(self) item['material'] = self.material item['size'] = self.size return item
def return_as_dictionary(self): '''Return fields as a dictionary''' output_dict = {} output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Returns product information as dictionary.""" output_dict = {} output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def return_as_dictionary(self): """Returns output dictionary with product info.""" output_dict = {} output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """Function returns Electronic Appliance inventory instance properties as a dictionary to be included in the inventory database.""" item = Inventory.return_as_dictionary(self) item['brand'] = self.brand item['voltage'] = self.voltage return item
def return_as_dictionary(self): ''' Return the ElectricAppliance class as a dictionary. ''' output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): '''Return Electric Appliances fields as a dictionary''' output_dict = {} output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def test_inventory(self): """Tests the creation of an instance for inventory object""" test_dict = { 'product_code': 6789, 'description': 'Horse', 'market_price': 50, 'rental_price': 10 } test_inv = Inventory(6789, 'Horse', 50, 10) self.assertEqual(test_dict, test_inv.return_as_dictionary())
def test_inventory_initialization(self): """ Tests for successful, accurate initalization of Inventory. """ new_product = Inventory(1, 'Chair', 100, 20) new_product_dict = new_product.return_as_dictionary() self.assertEqual(1, new_product_dict['product_code']) self.assertEqual('Chair', new_product_dict['description']) self.assertEqual(100, new_product_dict['market_price']) self.assertEqual(20, new_product_dict['rental_price'])
def return_as_dictionary(self): """ Return the current attributes of the instantiated class as a dictionary for processsing elsewhere. """ output_dict = Inventory.return_as_dictionary(self) output_dict['brand'] = self.brand output_dict['voltage'] = self.voltage return output_dict
def return_as_dictionary(self): """ Return the current attributes of the instantiated class as a dictionary for processsing elsewhere. """ output_dict = Inventory.return_as_dictionary(self) output_dict['material'] = self.material output_dict['size'] = self.size return output_dict
def test_inventory(self): """ tests inventory class returning a dict of all information about an item in the inventory""" testdict = { 'productcode': '5', 'description': 'shoe', 'marketprice': '15', 'rentalprice': '20', } inventory_test = Inventory(*testdict.values()) inventory_dict_test = inventory_test.return_as_dictionary() self.assertDictEqual(testdict, inventory_dict_test)
class InventoryClassTest(TestCase): """Testing the Inventory class.""" def test_inventory_class(self): self.test_item = Inventory("123", "Table", "329.99", "59.99") self.test_dict = self.test_item.return_as_dictionary() self.assertDictEqual( self.test_dict, { "product_code": "123", "description": "Table", "market_price": "329.99", "rental_price": "59.99" })
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_inventory_class(self): """Test for the Inventory class.""" inventory_test = Inventory("GI-2", "Table", 500, 60) inventory_test_dict = { "product_code": "GI-2", "description": "Table", "market_price": 500, "rental_price": 60 } self.assertDictEqual(vars(inventory_test), inventory_test_dict) self.assertDictEqual(inventory_test.return_as_dictionary(), inventory_test_dict)