def test_main_menu(self): # test the ability to add new items to the inventory main.FULL_INVENTORY = {} with patch('builtins.input', side_effect='1'): main.main_menu() with patch('builtins.input', side_effect=self.update_inventory[0]): main.addnew_item() with patch('builtins.input', side_effect=self.update_inventory[1]): main.addnew_item() self.assertEqual(self.FULL_INVENTORY, main.FULL_INVENTORY)
def test_main_menu(self): ''' test main menu options ''' main.FULL_INVENTORY = {} # test the ability to add new items to the inventory with patch('builtins.input', side_effect=self.update_inventory[0]): main.addnew_item() with patch('builtins.input', side_effect=self.update_inventory[1]): main.addnew_item() # assert that it is the same as the setup self.assertEqual(self.FULL_INVENTORY, main.FULL_INVENTORY) # assert adding non furniture or electric appliance works with patch('builtins.input', side_effect=self.update_inventory[2]): main.addnew_item() self.assertEqual(main.FULL_INVENTORY[3]['description'], 'hops') with patch('builtins.input', side_effect=self.update_inventory[3]): main.main_menu() self.assertEqual(main.FULL_INVENTORY[3]['rental_price'], 20) # add a new item to the inventory with patch('builtins.input', side_effect=[1]): main.item_info() # Trigger else statement in item_info() with patch('sys.stdout', new=io.StringIO()) as output: with patch('builtins.input', side_effect=['1']): main.item_info() self.assertEqual('Item not found in inventory\n', output.getvalue()) # test exit_program with self.assertRaises(SystemExit) as exit_program: main.exit_program() self.assertEqual(exit_program.exception.code, 0)
def test_addnew_furniture(self): """Defining what we will use as input to the addnew_item()""" input_furniture = ('444', 'bed', 150, 'y', 'wood', 'L') input_app = ('555', 'laptop', 50, 'n', 'y', 'samsung', 120) input_inventory = ('666', 'test', 5, 'n', 'n') #defining expected output expected_item_dic = { '444': { 'description': 'bed', 'market_price': 180.0, 'product_code': '444', 'rental_price': 150, 'material': 'wood', 'size': 'L' }, '555': { 'description': 'laptop', 'market_price': 120.0, 'product_code': '555', 'rental_price': 50, 'brand': 'samsung', 'voltage': 120 }, '666': { 'description': 'test', 'market_price': 10.0, 'product_code': '666', 'rental_price': 5 } } with patch('builtins.input', side_effect=input_furniture): # Creating empty FULL_INVENTORY dictionary main.FULL_INVENTORY = {} # patching item price with patch('inventory_management.market_prices.get_latest_price', return_value=180.0): main.addnew_item() self.assertDictEqual(main.FULL_INVENTORY['444'], expected_item_dic['444']) with patch('builtins.input', side_effect=input_app): # main.FULL_INVENTORY = {} with patch('inventory_management.market_prices.get_latest_price', return_value=120.0): main.addnew_item() self.assertDictEqual(main.FULL_INVENTORY['555'], expected_item_dic['555']) with patch('builtins.input', side_effect=input_inventory): with patch('inventory_management.market_prices.get_latest_price', return_value=10.0): main.addnew_item() self.assertEqual(main.FULL_INVENTORY['666'], expected_item_dic['666']) self.assertDictEqual(main.FULL_INVENTORY, expected_item_dic)
def test_addnew_item(self): # test the ability to add new items to the inventory with patch('builtins.input', side_effect=self.update_inventory[0]): main.addnew_item() with patch('builtins.input', side_effect=self.update_inventory[1]): main.addnew_item() self.assertEqual(self.FULL_INVENTORY, main.FULL_INVENTORY) with patch('builtins.input', side_effect=self.update_inventory[2]): main.addnew_item() self.assertEqual(main.FULL_INVENTORY[3]['description'], 'hops')
def test_add_simple_object(self): # creating a simple object with patch('builtins.input', side_effect=self.update_inventory[1]): main.addnew_item() self.assertEqual(main.FULL_INVENTORY[2]['description'], 'sofa')
def test_add_new_item(self): """Test add new item function in main module.""" # --- INPUTS BASED ON SEQUENCE OF MAIN UI QUESTIONS --- # Item code, item desc, rental price, is it furn (y/n), # is it elec app (y/n) inv_item = [1, 'Knife Set', 10, 'n', 'n'] # Item code, item desc, rental price, is it furn (y/n), # item material, item size furn_item = [2, 'Couch', 25, 'y', 'Cloth', 'L'] # Item code, item desc, rental price, is it furn (y/n), # is it elec app (y/n), brand, voltage elec_item = [3, 'Dryer', 100, 'n', 'y', 'Samsung', 12] # Check if inv item is successfully added as intended with patch('inventory_management.market_prices.get_latest_price', return_value=100): with patch('builtins.input', side_effect=inv_item): m.FULL_INVENTORY = {} m.addnew_item() i_dict = {} i_dict[1] = { 'item_code': 1, 'description': 'Knife Set', 'market_price': 100, 'rental_price': 10 } self.assertEqual(i_dict, m.FULL_INVENTORY) # Check if furniture item is successfully added as intended with patch('inventory_management.market_prices.get_latest_price', return_value=600): with patch('builtins.input', side_effect=furn_item): m.FULL_INVENTORY = {} m.addnew_item() f_dict = {} f_dict[2] = { 'item_code': 2, 'description': 'Couch', 'market_price': 600, 'rental_price': 25, 'material': 'Cloth', 'size': 'L' } self.assertEqual(f_dict, m.FULL_INVENTORY) # Check if electrical appliance is successfully added as intended with patch('inventory_management.market_prices.get_latest_price', return_value=1000): with patch('builtins.input', side_effect=elec_item): m.FULL_INVENTORY = {} m.addnew_item() e_dict = {} e_dict[3] = { 'item_code': 3, 'description': 'Dryer', 'market_price': 1000, 'rental_price': 100, 'brand': 'Samsung', 'voltage': 12 } self.assertEqual(e_dict, m.FULL_INVENTORY)
def test_integration(self): """Test all modules together.""" m.FULL_INVENTORY = {} # TEST ADDING FIRST ITEM (INVENTORY) with patch('builtins.input', side_effect=self.new_inv_item): with patch('inventory_management.market_prices.get_latest_price', return_value=100): m.addnew_item() self.assertEqual(m.FULL_INVENTORY, {'1': {'item_code': '1', 'description': 'Knife Set', 'market_price': 100, 'rental_price': 10 } } ) # TEST ADDING SECOND ITEM (FURNITURE) with patch('builtins.input', side_effect=self.new_furn_item): with patch('inventory_management.market_prices.get_latest_price', return_value=600): m.addnew_item() self.assertEqual(m.FULL_INVENTORY, {'1': {'item_code': '1', 'description': 'Knife Set', 'market_price': 100, 'rental_price': 10}, '2': {'item_code': '2', 'description': 'Couch', 'market_price': 600, 'rental_price': 25, 'material': 'Cloth', 'size': 'L'} } ) # TEST ADDING THIRD ITEM (ELECTRIC APPLIANCE) with patch('builtins.input', side_effect=self.new_elec_item): with patch('inventory_management.market_prices.get_latest_price', return_value=1000): m.addnew_item() self.assertEqual(m.FULL_INVENTORY, {'1': {'item_code': '1', 'description': 'Knife Set', 'market_price': 100, 'rental_price': 10}, '2': {'item_code': '2', 'description': 'Couch', 'market_price': 600, 'rental_price': 25, 'material': 'Cloth', 'size': 'L'}, '3': {'item_code': '3', 'description': 'Dryer', 'market_price': 1000, 'rental_price': 100, 'brand': 'Samsung', 'voltage': 12} } ) # TEST PULLING ITEM INFO # Expected output_found = 'item_code: 1\n' \ 'description: Knife Set\n' \ 'market_price: 100\n' \ 'rental_price: 10\n' output_not_found = 'Item not found in inventory\n' # Actual - Item Found with patch('builtins.input', side_effect='1'): with patch('sys.stdout', new_callable=io.StringIO) as real_out: m.item_info() self.assertEqual(output_found, real_out.getvalue()) # Actual - Item Not Found with patch('builtins.input', side_effect='4'): with patch('sys.stdout', new_callable=io.StringIO) as real_out: m.item_info() self.assertEqual(output_not_found, real_out.getvalue())