def test_get_price(cls): """ Test to ensure that on a given inventory set, get_price will return the correct value. This patches get_latest_prices since the method implementation is not functional """ main.FULL_INVENTORY = { 'CORN': { 'product_code': 'CORN', 'description': 'This is corn', 'market_price': 24, 'rental_price': 50 }, 'WATER': { 'product_code': 'WATER', 'description': 'This is water', 'market_price': 40, 'rental_price': 0, } } assert main.get_price('CORN') == 24 with patch('market_prices.get_latest_price', return_value=50): assert main.get_price('WHEAT') == 50
def test_get_price(self): """test get price """ self.price = MagicMock(return_value=24) self.price = '{}\n'.format(self.price()) with patch('sys.stdout', new=io.StringIO()) as actual_result: main.get_price() self.assertEqual(actual_result.getvalue(), self.price)
def test_get_price(self): """Test get_price function""" with mock.patch('sys.stdout') as fake_stdout: main.get_price('n') # A dummy input fake_stdout.assert_has_calls( [mock.call.write("Get price"), mock.call.write("\n")])
def test_get_price(self): # see if returns get price captured = io.StringIO() sys.stdout = captured get_price() sys.stdout = sys.__stdout__ mystring = "Get price\n" self.assertEqual(captured.getvalue(), mystring)
def test_get_price(self): """ Test get_price function """ input_info = [4, 'Stove', '1000', 'n', 'y', 'GE', '220'] with patch('builtins.input', side_effect=input_info): main.add_new_item() price = main.get_price(4) self.assertEqual(price, '1000')
def test_user_flow(cls): """ This integration test runs through the whole scenario end to end """ # add a furniture item user_inputs = ['CHAIR', 'This is a chair', 30, 'Y', 'wood', 'L'] with patch('builtins.input', side_effect=user_inputs): add_new_item() # add an eletrical appliance item user_inputs = ['TV', 'This is a tv', 300, 'N', 'Y', 'metal', 'S'] with patch('builtins.input', side_effect=user_inputs): add_new_item() # add a standard item user_inputs = ['CORN', 'This is corn', 30, 'N', 'n'] with patch('builtins.input', side_effect=user_inputs): add_new_item() # get the price of an item with patch('market_prices.get_latest_price', return_value=30): assert get_price('CORN') == 30 # get the item info user_inputs = [ '1', 'CORN', 'This is corn', 30, 'n', 'n', '2', 'CORN', 'q' ] with patch('builtins.input', side_effect=user_inputs): with patch('sys.stdout', new=io.StringIO()) as actual_results: main_menu() expected_result_strings = ["CORN", "This is corn", '30', '0'] for expected in expected_result_strings: assert actual_results.getvalue().find(expected)
def test_get_price(self): input_info = [2, 'stove', 1000, 'n', 'y', 'Steve Stoves', 220] with patch('builtins.input', side_effect=input_info): main.add_new_item() price = main.get_price(2) self.assertEqual(price, 1000)
def test_add_new_item(self): """ tests add new items to inventory inv == itemcode,descr,rentalprice,isFurn,isAppl furn == itemcode,descr,rentalprice,isFurn,isAppl,material,size appl == itemcode,descr,rentalprice,isFurn,isAppl,brand,voltage """ item_inv = ['1', 'Shirt', '50', 'n', 'n'] item_furn = ['2', 'Chair', '100', 'y', 'wood', 'L'] item_appl = ['3', 'Washer', '200', 'n', 'y', 'Maytag', '120'] with patch('builtins.input', side_effect=item_inv): main.add_new_item() with patch('builtins.input', side_effect=item_furn): main.add_new_item() with patch('builtins.input', side_effect=item_appl): main.add_new_item() test_dict = { '1': { 'product_code': '1', 'description': 'Shirt', 'market_price': 24, 'rental_price': '50' }, '2': { 'product_code': '2', 'description': 'Chair', 'market_price': 24, 'rental_price': '100', 'material': 'wood', 'size': 'L' }, '3': { 'product_code': '3', 'description': 'Washer', 'market_price': 24, 'rental_price': '200', 'brand': 'Maytag', 'voltage': '120' } } self.assertEqual(test_dict, main.return_full_inventory()) """ Test get_price """ self.assertEqual(main.get_price('test'), 24) """ test get inventory item info """ with patch('builtins.input', side_effect='2'): function = main.item_info() info = '\n'.join( ('product_code:2', 'description:Chair', 'market_price:24', 'rental_price:100', 'material:wood', 'size:L')) self.assertEqual(function, info) """ tests item info function when item code is not in the inventory """ with patch('builtins.input', side_effect='999'): function = main.item_info() self.assertEqual(function, 'Item not found in inventory') """ tests exit program """ with self.assertRaises(SystemExit): main.exit_program()
def test_get_price(self): # Given expected_value = 24 item_code = 32 # When result = main.get_price(item_code) # Then self.assertEqual(expected_value, result)
def test_integration(self): main.FULLINVENTORY = {} #test menu with patch('builtins.input', side_effect='1'): self.assertEqual(main.main_menu(), main.add_new_item) with patch('builtins.input', side_effect='2'): self.assertEqual(main.main_menu(), main.item_info) with patch('builtins.input', side_effect='q'): self.assertEqual(main.main_menu(), main.exit_program) #test add item with patch('builtins.input', side_effect=i_obj): main.add_new_item() with patch('builtins.input', side_effect=f_obj): main.add_new_item() with patch('builtins.input', side_effect=e_obj): main.add_new_item() self.assertEqual(main.FULLINVENTORY, expected) #reset fullinventory to just 400 product main.FULLINVENTORY = {'400': item_info} self.assertEqual(24, main.get_price(400)) # appliance item was added with mock.patch("builtins.print") as print_mock, mock.patch( "builtins.input") as input_mock: input_mock.return_value = "400" main.item_info() for k, val in item_info.items(): print_mock.assert_any_call(f"{k}:{val}") # item info for non existing product with mock.patch("builtins.print") as print_mock, mock.patch( "builtins.input") as input_mock: input_mock.return_value = "666" main.item_info() print_mock.assert_called_with("Item not found in inventory") #quit with self.assertRaises(SystemExit): main.exit_program()
def test_get_price(self): """Test for correct output of mock data""" self.assertEqual(main.get_price('item_code'), 24) main.get_price = MagicMock(return_value=30) self.assertEqual(main.get_price('item_code'), 30)
def test_get_price(self): """ Test getting the price of the requested item """ self.assertEqual(24, main.get_price(35))
def test_get_price(self): self.get_price = MagicMock(return_value=24) self.assertEqual(main.get_price(5), print('Get price'))
def test_get_price(self): main.get_price()
def test_get_pricec(self, mock_stdout): main.get_price() self.assertEqual(mock_stdout.getvalue(), "Get price\n")
def test_get_price(self): """Test get_price""" self.mp.get_latest_price = MagicMock(return_value=50) self.assertEqual(main.get_price('test'), 50)
def test_get_price(self): '''Tests the set_price function''' # Tests return value of 24 self.assertEqual(main.get_price('test'), 24)
def test_get_price(self): # Ensure that function returns 'Get price' with patch('sys.stdout', new=io.StringIO()) as output_string: get_price() self.assertEqual(output_string.getvalue(), 'Get price\n')
def test_getprice(self): with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout: tc.get_price(24) self.assertEqual(mock_stdout.getvalue(), 'Get price for item = 24.\n')
def test_get_price(self): """Test that the user can get the market price""" actual = main.get_price(1) expected = 24 self.assertEqual(actual, expected)
def test_get_price(self): with patch('sys.stdout', new=io.StringIO()) as fake_output: item_code = "1" m.get_latest_price = MagicMock() m.get_price(item_code) m.get_latest_price.assert_called_with(item_code)
def test_get_price(self): """Test get price program function in main module.""" with patch('sys.stdout', new_callable=io.StringIO) as real_out: m.get_price(1) self.assertEqual('Get price\n', real_out.getvalue())
def test_get_price(self): # ensure that market price is always 24 item_code_1 = main.FULL_INVENTORY[1] item_code_2 = self.FULL_INVENTORY[1] self.assertEqual(24, main.get_price(item_code_1)) self.assertEqual(24, main.get_price(item_code_2))
def test_integration(self): """ Test the full integration of the program""" # Given main.FULL_INVENTORY = {} item_1 = ("1", "1001", "Kumiko Panel", 5.00, "n", "n") item_2 = ("\n", "1", "1002", "Dining Room Table", 93.00, "y", "Walnut", "L") item_3 = ("\n", "1", "1003", "Desk lamp", 12.00, "n", "y", "LiteBrite", 110) expected_dict = { "1001": { "product_code": "1001", "description": "Kumiko Panel", "market_price": 24, "rental_price": 5.00, }, "1002": { "product_code": "1002", "description": "Dining Room Table", "market_price": 24, "rental_price": 93.00, "material": "Walnut", "size": "L", }, "1003": { "product_code": "1003", "description": "Desk lamp", "market_price": 24, "rental_price": 12.00, "brand": "LiteBrite", "voltage": 110, }, } expected_info = """product_code:1003 description:Desk lamp market_price:24 rental_price:12.0 brand:LiteBrite voltage:110 """ # When with patch("builtins.input", side_effect=item_1): main.main_menu()() with patch("builtins.input", side_effect=item_2): main.main_menu()() with patch("builtins.input", side_effect=item_3): main.main_menu()() with patch("builtins.input", side_effect="2"): self.assertEqual(main.item_info, main.main_menu()) market_prices.get_latest_price = MagicMock(return_value=300) self.assertEqual(300, main.get_price("1003")) with patch("builtins.input", side_effect=["1003"]): with patch("sys.stdout", new=io.StringIO()) as actual_result: main.item_info() self.assertEqual(expected_info, actual_result.getvalue()) with patch("builtins.input", side_effect=["1004"]): with patch("sys.stdout", new=io.StringIO()) as actual_result: main.item_info() self.assertEqual("Item not found in inventory\n", actual_result.getvalue()) with patch("builtins.input", side_effect=["q"]): with self.assertRaises(SystemExit): main.main_menu()() # self.assertEqual(main.exit_program,main.main_menu()) # Then self.assertEqual(expected_dict, main.FULL_INVENTORY)
def test_get_price(self): price = get_price("CL") self.assertEqual(price, 24)
def test_get_price(self): """Test the get_price function.""" self.assertEqual(main.get_price("A1"), 24)
def test_get_prices(self): """tests the get prices function""" self.assertEqual(main.get_price("1"), 24)
def test_get_price(self): self.assertEqual(24, main.get_price())
def test_get_price(self): self.assertEqual(main.get_price('123'), 24)
def test_get_price(self): """Test get price""" self.assertEqual(Main.get_price(20), 24)