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)
Esempio n. 2
0
 def test_main_menu1(self):
     with patch('builtins.input', side_effect="1"):
         self.assertEqual(main.main_menu().__name__, "add_new_item")
     with patch('builtins.input', side_effect="2"):
         self.assertEqual(main.main_menu().__name__, "item_info")
     with patch('builtins.input', side_effect="q"):
         self.assertEqual(main.main_menu().__name__, "exit_program")
 def test_main(self):
     """Test main_menu function """
     with mock.patch('builtins.input',
                     side_effect=['1', '1', '2', '3', 'n', 'y', '4', '5']):
         main.main_menu()
         self.assertEqual(main.FULL_INVENTORY['1']['product_code'], '1')
         self.assertEqual(main.FULL_INVENTORY['1']['market_price'], 24)
         self.assertEqual(main.FULL_INVENTORY['1']['brand'], '4')
         self.assertEqual(main.FULL_INVENTORY['1']['voltage'], '5')
     with mock.patch('builtins.input',
                     side_effect=['2', '2', '3', 'n', 'n', '4', '5']):
         main.main_menu('1')
         self.assertEqual(main.FULL_INVENTORY['2']['product_code'], '2')
         self.assertEqual(main.FULL_INVENTORY['2']['market_price'], 24)
     with mock.patch('builtins.input',
                     side_effect=['3', '2', '3', 'y', '4', '5']):
         main.main_menu('1')
         self.assertEqual(main.FULL_INVENTORY['3']['product_code'], '3')
         self.assertEqual(main.FULL_INVENTORY['3']['market_price'], 24)
         self.assertEqual(main.FULL_INVENTORY['3']['material'], '4')
         self.assertEqual(main.FULL_INVENTORY['3']['size'], '5')
     with mock.patch('builtins.input',
                     side_effect=['q', '2', '3', 'y', '4', '5']):
         with self.assertRaises(SystemExit):
             main.main_menu()
             self.assertRaises(SystemExit, main.exit_program())
     with mock.patch('builtins.input',
                     side_effect=['2', '2', '3', 'y', '4', '5']):
         main.main_menu()
         self.assertEqual(main.FULL_INVENTORY['3']['product_code'], '3')
         self.assertEqual(main.FULL_INVENTORY['3']['market_price'], 24)
         self.assertEqual(main.FULL_INVENTORY['3']['material'], '4')
         self.assertEqual(main.FULL_INVENTORY['3']['size'], '5')
    def test_module(self):
        # testing option 1: add_new_item().
        with patch('builtins.input', side_effect='1'):
            self.assertEqual(main.main_menu().__name__, 'add_new_item')

        main.get_latest_price = MagicMock()
        main.get_latest_price.return_value = 24
        electric_appliance_inputs = ['001', 'oven', 12, 'n', 'y', 'GE', 120]
        with patch('builtins.input', side_effect=electric_appliance_inputs):
            main.add_new_item()
            self.assertEqual(len(main.FULL_INVENTORY), 1)
            self.assertEqual(main.FULL_INVENTORY[0].product_code, '001')
            self.assertEqual(main.FULL_INVENTORY[0].description, 'oven')
            self.assertEqual(main.FULL_INVENTORY[0].market_price, 24)
            self.assertEqual(main.FULL_INVENTORY[0].rental_price, 12)
            self.assertEqual(main.FULL_INVENTORY[0].brand, 'GE')
            self.assertEqual(main.FULL_INVENTORY[0].voltage, 120)

        # testing option 2: item_info().
        with patch('builtins.input', side_effect='2'):
            self.assertEqual(main.main_menu().__name__, 'item_info')
            with patch('builtins.input', side_effect=['001']):
                with patch('builtins.print') as fakeoutput:
                    main.item_info()  # print the information of item 001
                    fakeoutput.assert_called_with(main.FULL_INVENTORY[0])

        # testing option 3: exit_program().
        with patch('builtins.input', side_effect='q'):
            self.assertEqual(main.main_menu().__name__, 'exit_program')
        with self.assertRaises(SystemExit) as texit:
            main.exit_program()
            the_exception = texit.exception
            self.assertEqual(the_exception.code, 3)
Esempio n. 5
0
 def test_main_menu(self):
     with patch('builtins.input', side_effect='1'):
         self.assertEqual(main.main_menu().__name__, 'add_new_item')
     with patch('builtins.input', side_effect='2'):
         self.assertEqual(main.main_menu().__name__, 'item_info')
     with patch('builtins.input', side_effect='q'):
         self.assertEqual(main.main_menu().__name__, 'exit_program')
    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)
Esempio n. 7
0
 def test_main_menu(self):
     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)
Esempio n. 8
0
 def test_mainMenu(self):
     """
     Tests main menu function
     """
     with mock.patch('builtins.input', side_effect = ['1', '2', 'q']):
         self.assertEqual(main_menu(), add_new_item)
         self.assertEqual(main_menu(), item_info)
         self.assertEqual(main_menu(), exit_program)
Esempio n. 9
0
 def test_menu(self):
     """Test the main menu function."""
     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)
Esempio n. 10
0
 def test_main_menu(self):  # Tests main menu setup
     with patch('builtins.input',
                side_effect='1'):  # side_effect is the input value stored
         self.assertIs(main.main_menu(), main.add_new_item)
     with patch('builtins.input', side_effect='2'):
         self.assertIs(main.main_menu(), main.item_info)
     with patch('builtins.input', side_effect='q'):
         self.assertIs(main.main_menu(), main.exit_program)
Esempio n. 11
0
    def test_main(self):
        '''
        tests a typical sequence of a user entering two new items
        each mock starts with user input 1 for add new item to inventory
        followed by details for a piece of furniture then appliance
        lastly a mock looks up item info for item 001
        '''
        with patch('builtins.input',
                   side_effect=('1', '001', 'bench', 63, 'y', 'wood', 'XL')):
            main.main_menu()()
            self.assertEqual(
                main.FULL_INVENTORY, {
                    '001': {
                        'product_code': '001',
                        'description': 'bench',
                        'market_price': 24,
                        'rental_price': 63,
                        'material': 'wood',
                        'size': 'XL'
                    }
                })

        with patch('builtins.input',
                   side_effect=('1', '024', 'tv', 299, 'n', 'y', 'tvsrus',
                                110)):
            with patch('inventory_management.market_prices.get_latest_price',
                       return_value=859):
                main.main_menu()()
            self.assertEqual(
                main.FULL_INVENTORY, {
                    '001': {
                        'product_code': '001',
                        'description': 'bench',
                        'market_price': 24,
                        'rental_price': 63,
                        'material': 'wood',
                        'size': 'XL'
                    },
                    '024': {
                        'product_code': '024',
                        'description': 'tv',
                        'market_price': 859,
                        'rental_price': 299,
                        'brand': 'tvsrus',
                        'voltage': 110
                    }
                })

        with patch('builtins.input', side_effect=['001']):
            with patch('sys.stdout', new=io.StringIO()) as input_result:
                main.item_info()
        self.assertEqual(
            input_result.getvalue(), 'product_code:001\n'
            'description:bench\n'
            'market_price:24\n'
            'rental_price:63\n'
            'material:wood\n'
            'size:XL\n')
Esempio n. 12
0
    def test_main_menu(self):
        self.main.get_user_input = MagicMock(return_value="1")
        self.assertEqual(main.main_menu(), main.add_new_item)

        self.main.get_user_input.return_value = "2"
        self.assertEqual(main.main_menu(), main.item_info)

        self.main.get_user_input.return_value = "q"
        self.assertEqual(main.main_menu(), main.exit_program)
    def test_main_menu(self):
        with patch("builtins.input", side_effect="1"):
            self.assertEqual(main_menu(), add_new_item)

        with patch("builtins.input", side_effect="2"):
            self.assertEqual(main_menu(), item_info)

        with patch("builtins.input", side_effect="q"):
            self.assertEqual(main_menu(), exit_program)
Esempio n. 14
0
    def test_A_main_menu(self):
        """ Tests main menu selection functionality """

        with patch('builtins.input', side_effect='1'):
            self.assertEqual(menu.main_menu(), menu.add_new_item)
        with patch('builtins.input', side_effect='2'):
            self.assertEqual(menu.main_menu(), menu.item_info)
        with patch('builtins.input', side_effect='q'):
            self.assertEqual(menu.main_menu(), menu.exit_program)
Esempio n. 15
0
 def test_main_menu(self):
     """Test main UI of main module."""
     print('test_main_menu')
     with patch('builtins.input', side_effect='1'):
         self.assertEqual(m.main_menu(), m.addnew_item)
     with patch('builtins.input', side_effect='2'):
         self.assertEqual(m.main_menu(), m.item_info)
     with patch('builtins.input', side_effect='q'):
         self.assertEqual(m.main_menu(), m.exit_program)
 def test_main_menu(self):
     """
     Tests main.main_menu()
     """
     self.assertEqual(main.main_menu('1'), main.add_new_item)
     self.assertEqual(main.main_menu('2'), main.item_info)
     self.assertEqual(main.main_menu('q'), main.exit_program)
     with patch('builtins.input', lambda x: '1'):
         menu = main.main_menu()
         self.assertEqual(menu, main.add_new_item)
Esempio n. 17
0
    def test_main_menu(self):
        """Test menu options use correct methods"""
        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)
Esempio n. 18
0
 def test_main(self):
     """Test main_menu function """
     with mock.patch('builtins.input', side_effect=['0', 'q']):
         with mock.patch('sys.stdout'):
             with self.assertRaises(SystemExit):
                 main.main_menu()
                 mock.call.write(
                     "Please choose from the following options (1, 2, q)"
                 ).assert_called_once()
                 self.assertRaises(SystemExit, main.exit_program())
Esempio n. 19
0
    def test_main_menu(self):
        """Test for the main menu selections  """

        with patch('builtins.input', side_effect='1'):
            self.assertEqual(main.add_new_item, main.main_menu())

        with patch('builtins.input', side_effect='2'):
            self.assertEqual(main.item_info, main.main_menu())

        with patch('builtins.input', side_effect='q'):
            self.assertEqual(main.exit_program, main.main_menu())
Esempio n. 20
0
    def test_main_menu(self):
        """Tests navigation of main menu"""
        with patch("builtins.input") as handle_input:
            handle_input.return_value = "1"
            self.assertIs(Main.add_new_item, Main.main_menu())

            handle_input.return_value = "2"
            self.assertIs(Main.item_info, Main.main_menu())

            handle_input.return_value = "q"
            self.assertIs(Main.exit_program, Main.main_menu())
Esempio n. 21
0
 def test_main_menu(self):
     """tests the main menu functionality"""
     with patch('builtins.input', side_effect='1'):
         function = main.main_menu()
     self.assertEqual(function.__name__, 'add_new_item')
     with patch('builtins.input', side_effect='2'):
         function = main.main_menu()
     self.assertEqual(function.__name__, 'item_info')
     with patch('builtins.input', side_effect='q'):
         function = main.main_menu()
     self.assertEqual(function.__name__, 'exit_program')
Esempio n. 22
0
    def test_main_menu(self):
        '''Test that each input results in the corresponding function'''

        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)
Esempio n. 23
0
    def test_main_menu(self):
        """ checks the correct menu selections are returned """
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = '1'
            self.assertEqual(main.main_menu(), main.add_new_item)

            mock_input.side_effect = '2'
            self.assertEqual(main.main_menu(), main.item_info)

            mock_input.side_effect = 'q'
            self.assertEqual(main.main_menu(), main.exit_program)
    def test_main_menu(self):
        """Test that the user input selects the appropriate menu option"""

        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)
Esempio n. 25
0
    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)
Esempio n. 26
0
    def test_main_menu(self):
        """Test menu options call the correct methods"""

        # Use context managers (with + indentation) to define the patch scope
        # The builtins module is home to input().
        # Because main calls input from builtins, we need to patch builtins.
        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)
Esempio n. 27
0
    def test_main_menu_option_2(self, mock_input):
        """ Test main menu option 2: item_info """
        printout = 'Please choose from the following options 1, 2, q:\n' \
                   '1. Add a new item to the inventory\n' \
                   '2. Get item information\n' \
                   'q. Quit\n' \
                   'product code:3\ndescription:Sofa\nmarket price:1000\n' \
                   'rental price:50\nmaterial:Leather\nsize:XL'

        with patch('sys.stdout', new=io.StringIO()) as fake_output:
            m.main_menu()()

        assert fake_output.getvalue().strip() == printout
    def test_main_menu(self):
        """
        Validates the Main Menu.
        """
        with patch("builtins.input") as handle_input:
            handle_input.return_value = "1"
            self.assertIs(Main.add_new_item, Main.main_menu())

            handle_input.return_value = "2"
            self.assertIs(Main.item_info, Main.main_menu())

            handle_input.return_value = "q"
            self.assertIs(Main.exit_program, Main.main_menu())
Esempio n. 29
0
 def test_main_menu(self):
     optional_prompts = ('a', 'b', 'c')
     for prompts in optional_prompts:
         if prompts == 'a':
             return 'Apple'
         elif prompts == 'b':
             return 'Boy'
         else:
             return 'Cat'
     main.main_menu()
     self.assertEqual(main.main_menu('a'), 'Apple')
     self.assertEqual(main.main_menu('b'), 'Boy')
     self.assertEqual(main.main_menu('c'), 'Cat')
Esempio n. 30
0
    def test_main_menu(self):
        '''Tests the main_menu function'''

        # Tests the menu option '1'
        with patch('builtins.input', side_effect='1'):
            self.assertEqual(main.main_menu(), main.add_new_item)

        # Tests the menu option '2'
        with patch('builtins.input', side_effect='2'):
            self.assertEqual(main.main_menu(), main.item_info)

        # Tests the menu option 'q'
        with patch('builtins.input', side_effect='q'):
            self.assertEqual(main.main_menu(), main.exit_program)