def test_add_furniture(self):
     """ testing the adding of an inventory item """
     furniture_input = ['1', 'Chair', 25, 'Y', 'WOOD', 'XL']
     expected = {'1': {'productCode': '1', 'description': 'Chair', 'marketPrice': 24,
                       'rentalPrice': 25, 'material': 'WOOD', 'size': 'XL'}}
     with patch('builtins.input', side_effect=furniture_input):
         main.addnewitem()
     self.assertEqual(main.FULLINVENTORY, expected)
 def test_add_inventory(self):
     """ testing the adding of an inventory item """
     inventory_input = ['1', 'Frame', 25, 'N', 'N']
     expected = {'1': {'productCode': '1', 'description': 'Frame',
                       'marketPrice': 24, 'rentalPrice': 25}}
     with patch('builtins.input', side_effect=inventory_input):
         main.addnewitem()
     self.assertEqual(main.FULLINVENTORY, expected)
 def test_add_appliance(self):
     """ testing the adding of an appliance item """
     appliance_input = ['1', 'Toaster', 25, 'N', 'Y', 'LG', '220V']
     expected = {'1': {'productCode': '1', 'description': 'Toaster', 'marketPrice': 24,
                       'rentalPrice': 25, 'brand': 'LG', 'voltage': '220V'}}
     with patch('builtins.input', side_effect=appliance_input):
         main.addnewitem()
     self.assertEqual(main.FULLINVENTORY, expected)
 def test_not_in_item_info(self):
     """ testing return value of item info """
     inventory_input = ['1', 'Frame', 25, 'N', 'N', '2']
     expected = 'Item not found in inventory\n'
     with patch('builtins.input', side_effect=inventory_input):
         main.addnewitem()
         with patch('sys.stdout', new=io.StringIO()) as print_out:
             main.iteminfo()
             self.assertEqual(print_out.getvalue(), expected)
 def test_item_info(self):
     """ testing return value of item info """
     inventory_input = ['1', 'Frame', 25, 'N', 'N', '1']
     expected = 'productCode:1\ndescription:Frame\nmarketPrice:24\nrentalPrice:25\n'
     with patch('builtins.input', side_effect=inventory_input):
         main.addnewitem()
         with patch('sys.stdout', new=io.StringIO()) as print_out:
             main.iteminfo()
             self.assertEqual(print_out.getvalue(), expected)
Beispiel #6
0
        def test_add_new(self):
            '''
            method doc string
            '''

            while True:
                try:
                    with patch('builtins.input', side_effect='1'):
                        self.assertEqual(mm.mainmenu(), mm.addnewitem())
                except StopIteration as error:
                    return error
Beispiel #7
0
    def test_inventory_integration(self):
        ''' Function to test integration of inventory management '''
        inventory_input = ['1', 'Frame', 25, 'N', 'N']
        appliance_input = ['2', 'Toaster', 25, 'N', 'Y', 'LG', '220V']
        furniture_input = ['3', 'Chair', 25, 'Y', 'WOOD', 'XL']
        expected_app = {'productCode': '2', 'description': 'Toaster', 'marketPrice': 24,
                        'rentalPrice': 25, 'brand': 'LG', 'voltage': '220V'}
        expected_furn = {'productCode': '3', 'description': 'Chair', 'marketPrice': 24,
                         'rentalPrice': 25, 'material': 'WOOD', 'size': 'XL'}
        expected_inv = {'productCode': '1', 'description': 'Frame',
                        'marketPrice': 24, 'rentalPrice': 25}
        full_inventory = {'1': {'productCode': '1', 'description': 'Frame',
                                'marketPrice': 24, 'rentalPrice': 25},
                          '2': {'productCode': '2',
                                'brand': 'LG', 'description': 'Toaster',
                                'marketPrice': 24,
                                'rentalPrice': 25, 'voltage': '220V'},
                          '3': {'productCode': '3',
                                'description': 'Chair',
                                'marketPrice': 24, 'rentalPrice': 25,
                                'material': 'WOOD', 'size': 'XL'}}

        with patch('builtins.input', side_effect=inventory_input):
            main.addnewitem()
        with patch('builtins.input', side_effect=appliance_input):
            main.addnewitem()
        with patch('builtins.input', side_effect=furniture_input):
            main.addnewitem()
        self.assertEqual(main.FULLINVENTORY['3'], expected_furn)
        self.assertEqual(main.FULLINVENTORY['2'], expected_app)
        self.assertEqual(main.FULLINVENTORY['1'], expected_inv)
        with patch('builtins.input', side_effect=['4', '1']):
            with patch('sys.stdout', new=io.StringIO()) as print_out:
                main.iteminfo()
                self.assertEqual(print_out.getvalue(),
                                 'Item not found in inventory\n')
            with patch('sys.stdout', new=io.StringIO()) as print_out:
                main.iteminfo()
                self.assertEqual(print_out.getvalue(),
                                 'productCode:1\ndescription:Frame\nmarketPrice:24\nrentalPrice:25\n')
        self.assertEqual(main.FULLINVENTORY, full_inventory)
        with patch('sys.stdout', new=io.StringIO()) as print_out:
            main.getprice()
            self.assertEqual(print_out.getvalue(), 'Get price\n')
 def test_addnewitem(self):
     furniture_item = [1,"Chair","2","y","wood","XL"]
     electric_item = [2, "Blender", "3", "n", "y", "samsung", "200v"]
     other_item = [3, "TheKidFromHomeAlone", "15/hr", "n", "n"]
     with patch ("inventory_management.market_prices.get_latest_price", return_value=123):
         with patch("sys.stdout", new_callable=io.StringIO) as value:
             with patch("builtins.input", side_effect=furniture_item):
                     main.FULL_INVENTORY = {}
                     main.addnewitem()
                     self.assertEqual(main.FULL_INVENTORY[1],
                                      {"productcode":1,
                                       'description':"Chair",
                                      'marketprice':123,
                                      'rentalprice':"2",
                                      'material':"wood",
                                      'size':"XL"}
                                      )
                     self.assertEqual(value.getvalue(), "New inventory item added\n")
             with patch("builtins.input", side_effect=electric_item):
                 main.FULL_INVENTORY = {}
                 main.addnewitem()
                 self.assertEqual(main.FULL_INVENTORY[2],
                                  {"productcode":2,
                                   'description':"Blender",
                                  'marketprice':123,
                                  'rentalprice':"3",
                                  'brand':"samsung",
                                  'voltage':"200v"}
                                  )
             with patch("builtins.input", side_effect=other_item):
                 main.FULL_INVENTORY = {}
                 main.addnewitem()
                 self.assertEqual(main.FULL_INVENTORY[3],
                                  {"productcode":3,
                                   'description':"TheKidFromHomeAlone",
                                  'marketprice':123,
                                  'rentalprice':"15/hr",}
                                  )