Beispiel #1
0
    def test_integration(self):
        main.FULLINVENTORY = {}
        inv_details = ['001', 'Painting', 6.0, 'n', 'n']
        app_details = ['002', 'Microwave', 5.0, 'n', 'y', 'GE', 3.2]
        furn_details = ['003', 'Desk', 15.0, 'y', 'Mahogany', 'L']

        expected_dict = {
            '001': {
                'product_code': '001',
                'description': 'Painting',
                'market_price': 24,
                'rental_price': 6.0
            },
            '002': {
                'product_code': '002',
                'description': 'Microwave',
                'market_price': 24,
                'rental_price': 5.0,
                'brand': 'GE',
                'voltage': 3.2
            },
            '003': {
                'product_code': '003',
                'description': 'Desk',
                'market_price': 24,
                'rental_price': 15.0,
                'material': 'Mahogany',
                'size': 'L'
            }
        }
        #all are set to 24 dollars since the return value isn't overriden
        # Expected output for searching inventory.
        test_string = ('product_code: 002\n'
                       'description: Microwave\n'
                       'market_price: 24\n'
                       'rental_price: 5.0\n'
                       'brand: GE\n'
                       'voltage: 3.2\n')

        # Test that a blank full inventory is created.
        with patch('builtins.input', side_effect=inv_details):
            main.add_new_item()
        with patch('builtins.input', side_effect=app_details):
            main.add_new_item()
        with patch('builtins.input', side_effect=furn_details):
            main.add_new_item()

        # Test that all items were added to the full inventory.
        self.assertEqual(main.FULLINVENTORY, expected_dict)

        # Test that an applicance item was added to the full inventory.
        with patch('builtins.input', side_effect=['002']):
            self.assertEqual(main.item_info(), print(test_string))
Beispiel #2
0
 def test_multi_creation_lookup(self, mock_input):
     with patch('sys.stdout', new=StringIO()) as fake_output:
         main.get_latest_price = MagicMock(return_value='FakePrice')
         main.add_new_item()
         assert main.FULL_INVENTORY == inventory_elec
         main.add_new_item()
         assert main.FULL_INVENTORY == inventory_elec_furn
         main.add_new_item()
         assert main.FULL_INVENTORY == inventory_elec_furn_gen
         main.item_info()
         assert fake_output.getvalue().strip() == stdout_statement
         main.FULL_INVENTORY = {}
    def test_user_run(self):
        """This emulates a hypothetical users behavior."""
        
        #Inputs and expected values
        user_in_1 = ['qws', '1']
        user_in_2 = ['2222', 'new generic product', '60.00', 'n', 'n']
        user_in_3 = ['3333', 'new electric product', '100.00', 'n', 'y', 'Atari', '120 volts']
        user_in_4 = ['4444', 'new furniture product', '40.00', 'y', 'cedar', 'L']
        expected_dict_2 = {'product_code': '2222', 'description': 'new generic product',
                           'market_price': 24, 'rental_price': '60.00'}
        expected_dict_3 = {'product_code': '3333', 'description': 'new electric product',
                           'market_price':24, 'rental_price': '100.00', 'brand': 'Atari',
                           'voltage': '120 volts'}
        expected_dict_4 = {'product_code': '4444', 'description': 'new furniture product',
                           'market_price': 24, 'rental_price': '40.00', 'material': 'cedar',
                           'size': 'L'}
        target_1 = 'product_code:3333\ndescription:new electric product\n'
        target_2 = 'market_price:24\nrental_price:100.00\nbrand:Atari\n'
        target_3 = 'voltage:120 volts\n'
        info_target = target_1+target_2+target_3
        
        #try out the program 
        with patch('builtins.input', side_effect=user_in_1):
            main_menu()

            #adding items
            with patch('builtins.input', side_effect=user_in_2):
                add_new_item()
                self.assertEqual(expected_dict_2, FULL_INVENTORY['2222'])      
            with patch('builtins.input', side_effect=user_in_3):
                add_new_item()
                self.assertEqual(expected_dict_3, FULL_INVENTORY['3333']) 
            with patch('builtins.input', side_effect=user_in_4):
                add_new_item()
                self.assertEqual(expected_dict_4, FULL_INVENTORY['4444']) 
                            
            #print(FULL_INVENTORY) 
            
        #getting an item's info
        with patch('builtins.input', side_effect='2'):
            main_menu()
            with patch('builtins.input', side_effect=user_in_3):
                with patch('sys.stdout', new=io.StringIO()) as print_result:
                    item_info()
        self.assertEqual(info_target, print_result.getvalue())
        
        #quitting the program
        with patch('builtins.input', side_effect='q'):
            main_menu()
            with self.assertRaises(SystemExit):
                exit_program()
    def test_add_new_items(self):
        Inventory = MagicMock(return_value=0)
        new_item = Inventory(**item_info)
        Inventory.assert_called_with(product_code='400',
                                     description='refrigerator',
                                     market_price='800.00',
                                     rental_price='300.00')

        with patch('market_prices.get_latest_price', return_value=40.0):
            with patch('builtins.input', side_effect=e_obj):
                e_dict = {}
                main.FULLINVENTORY = {}
                main.add_new_item()
                e_dict['100'] = {
                    'product_code': '100',
                    'description': 'lamp',
                    'market_price': 40.0,
                    'rental_price': 10.0,
                    'brand': 'Decor Therapy',
                    'voltage': 120
                }
                self.assertEqual(e_dict, main.FULLINVENTORY)

        with patch('market_prices.get_latest_price', return_value=600.0):
            with patch('builtins.input', side_effect=f_obj):
                f_dict = {}
                main.FULLINVENTORY = {}
                main.add_new_item()
                f_dict['200'] = {
                    'product_code': '200',
                    'description': 'beanbag',
                    'market_price': 600.0,
                    'rental_price': 100.0,
                    'material': 'faux fur',
                    'size': 'L'
                }
                self.assertEqual(f_dict, main.FULLINVENTORY)

        with patch('market_prices.get_latest_price', return_value=60.0):
            with patch('builtins.input', side_effect=i_obj):
                i_dict = {}
                main.FULLINVENTORY = {}
                main.add_new_item()
                i_dict['300'] = {
                    'product_code': '300',
                    'description': 'recliner',
                    'market_price': 60.0,
                    'rental_price': 20.0
                }
                self.assertEqual(i_dict, main.FULLINVENTORY)
Beispiel #5
0
 def test_add_new_item(self):
     """Test the add new method for furniture and appliances."""
     user_input_1 = ("001", "table", "$3", 'y', "wood", "L")
     furniture_dict = {
         "001": {
             "product_code": "001",
             "description": "table",
             "market_price": 24,
             "rental_price": "$3",
             "material": "wood",
             "size": "L"
         }
     }
     with patch("builtins.input", side_effect=user_input_1):
         main.add_new_item()
         self.assertEqual(main.FULL_INVENTORY, furniture_dict)
     user_input_2 = ("001", "table", "$3", "n", "n")
     inventory_dict = {
         "001": {
             "product_code": "001",
             "description": "table",
             "market_price": 24,
             "rental_price": "$3"
         }
     }
     with patch("builtins.input", side_effect=user_input_2):
         main.add_new_item()
         self.assertEqual(main.FULL_INVENTORY, inventory_dict)
     user_input_3 = ("003", "battery", "$5", "n", "y", "legend", "20V")
     inventory_dict = {
         "001": {
             "product_code": "001",
             "description": "table",
             "market_price": 24,
             "rental_price": "$3"
         },
         "003": {
             "product_code": "003",
             "description": "battery",
             "market_price": 24,
             "rental_price": "$5",
             "brand": "legend",
             "voltage": "20V"
         }
     }
     with patch("builtins.input", side_effect=user_input_3):
         main.add_new_item()
         self.assertEqual(main.FULL_INVENTORY, inventory_dict)
Beispiel #6
0
    def test_add_new_item(self):
        # test adding regular item
        reg_item = ['10', 'reg_item', '10.00', 'n', 'n']
        comp_dict = {
            '10': {
                'product_code': '10',
                'description': 'reg_item',
                'market_price': 24,
                'rental_price': '10.00'
            }
        }

        with mock.patch('builtins.input', side_effect=reg_item):
            main.add_new_item()

        self.assertEqual(FULL_INVENTORY, comp_dict)

        # test adding electrical appliance
        electrical_item = ['50', 'elec_item', '30.00', 'n', 'y', 'LG', '240']
        comp_dict['50'] = {
            'product_code': '50',
            'description': 'elec_item',
            'market_price': 24,
            'rental_price': '30.00',
            'brand': 'LG',
            'voltage': '240'
        }

        with mock.patch('builtins.input', side_effect=electrical_item):
            main.add_new_item()

        self.assertEqual(FULL_INVENTORY, comp_dict)

        # test adding furniture
        furniture_item = ['100', 'furn_item', '5.00', 'y', 'cloth', 'm']
        comp_dict['100'] = {
            'product_code': '100',
            'description': 'furn_item',
            'market_price': 24,
            'rental_price': '5.00',
            'material': 'cloth',
            'size': 'm'
        }

        with mock.patch('builtins.input', side_effect=furniture_item):
            main.add_new_item()

        self.assertEqual(FULL_INVENTORY, comp_dict)
Beispiel #7
0
 def test_add_new_item(self):
     """Compare expected add items against FULL INVENTORY dict."""
     with patch('builtins.input', side_effect=self.test_inputs_furniture):
         add_new_item()
         self.assertDictEqual(FULL_INVENTORY[self.test_inputs_furniture[0]],
                              self.test_dict_furniture)
     with patch('builtins.input',
                side_effect=self.test_inputs_electrical_appliances):
         add_new_item()
         self.assertDictEqual(
             FULL_INVENTORY[self.test_inputs_electrical_appliances[0]],
             self.test_dict_electric_appliances)
     with patch('builtins.input', side_effect=self.test_inputs_inventory):
         add_new_item()
         self.assertDictEqual(FULL_INVENTORY[self.test_inputs_inventory[0]],
                              self.test_dict_inventory)
Beispiel #8
0
    def test_add_new_item(self):
        electric_appliance = [1, "item", 5, "n", "y", "brand", 5.5]
        furniture = [1, "item", 5, "y", "material", "XL"]
        inventory = [1, "item", 5, "n", "n"]

        with patch('builtins.input', side_effect=electric_appliance):
            main.FULL_INVENTORY = {}
            main.add_new_item()
            test_dict = {
                1: {
                    'product_code': 1,
                    'description': "item",
                    'market_price': 24,
                    'rental_price': 5,
                    'brand': "brand",
                    'voltage': 5.5
                }
            }
            self.assertEqual(main.FULL_INVENTORY, test_dict)

        with patch('builtins.input', side_effect=furniture):
            main.FULL_INVENTORY = {}
            main.add_new_item()
            test_dict = {
                1: {
                    'product_code': 1,
                    'description': "item",
                    'market_price': 24,
                    'rental_price': 5,
                    'material': "material",
                    'size': "XL"
                }
            }
            self.assertEqual(main.FULL_INVENTORY, test_dict)

        with patch('builtins.input', side_effect=inventory):
            main.FULL_INVENTORY = {}
            main.add_new_item()
            test_dict = {
                1: {
                    'product_code': 1,
                    'description': "item",
                    'market_price': 24,
                    'rental_price': 5
                }
            }
            self.assertEqual(main.FULL_INVENTORY, test_dict)
    def test_add_new_item(self):
        '''Tests the add_nem_item function'''

        test_dict = {
            'bs12': {
                'product_code': 'bs12',
                'description': 'Bed Sheets',
                'market_price': 24,
                'rental_price': 4.99
            },
            'ch02': {
                'product_code': 'ch02',
                'description': 'chair',
                'market_price': 24,
                'rental_price': 5.99,
                'material': 'wood',
                'size': 'XL'
            },
            'rf03': {
                'product_code': 'rf03',
                'description': 'refrigerator',
                'market_price': 24,
                'rental_price': 145.99,
                'brand': 'GE',
                'voltage': 110
            }
        }

        # Tests the add new item function for an inventory item
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = ['bs12', 'Bed Sheets', 4.99, 'n', 'n']
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['bs12'], test_dict['bs12'])

        # Tests the add new item function for a furniture item
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = ['ch02', 'chair', 5.99, 'y', 'wood', 'XL']
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['ch02'], test_dict['ch02'])

        # Tests the add new item function for an electrical appliance item
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = [
                'rf03', 'refrigerator', 145.99, 'n', 'y', 'GE', 110
            ]
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['rf03'], test_dict['rf03'])
    def test_main(self):
        main.FULL_INVENTORY = {}

        test_furniture = ['BigOlCouch', 'Big, old.', 13, 'Y', 'wood', 'XXL']
        test_electric = ['ABC', 'Meh', 0.99, 'N', 'Y', 'VGood', '220']
        test_inventory = ['BiggerOlCouch', 'Bigger, old.', 99.99, 'N', 'N']

        inventory_dict = {
            'test_furniture': {
                'productCode': 'BigOlCouch',
                'description': 'Big, old.',
                'marketPrice': 24,
                'rentalPrice': 13,
                'material': 'wood',
                'size': 'XXL'
            },
            'test_electric': {
                'productCode': 'ABC',
                'description': 'Meh',
                'marketPrice': 24,
                'rentalPrice': 0.99,
                'brand': 'VGood',
                'voltage': '220'
            },
            'test_inventory': {
                'productCode': 'BiggerOlCouch',
                'description': 'Bigger, old.',
                'marketPrice': 24,
                'rentalPrice': 99.99
            }
        }

        with patch('builtins.input', side_effect=test_furniture):
            main.add_new_item()
        with patch('builtins.input', side_effect=test_electric):
            main.add_new_item()
        with patch('builtins.input', side_effect=test_inventory):
            main.add_new_item()

        self.assertEqual(main.FULL_INVENTORY['BigOlCouch'],
                         inventory_dict['test_furniture'])
        self.assertEqual(main.FULL_INVENTORY['ABC'],
                         inventory_dict['test_electric'])
        self.assertEqual(main.FULL_INVENTORY['BiggerOlCouch'],
                         inventory_dict['test_inventory'])
    def test_add_new_items(self):

        # Test adding furniture item to the full_inventory
        furniture_inputs = (123, "sample description", "sample rental price",
                            "y", "sample material", "sample size")

        sample_inventory = {123: {'product_code': 123,
                          'description': "sample description",
                          'market_price': 24,
                          'rental_price': "sample rental price",
                          'material': "sample material",
                          'size': "sample size"}}

        with patch('builtins.input', side_effect=furniture_inputs):
            main.add_new_item()
        self.assertEqual(main.full_inventory, sample_inventory)

        # Test adding electronic appliance item to the full_inventory
        electronic_app_inputs = (122, "sample description",
                                 "sample rental price", "n", "y",
                                 "sample brand", "sample voltage")

        sample_inventory[122] = {'product_code': 122,
                          'description': "sample description",
                          'market_price': 24,
                          'rental_price': "sample rental price",
                          'brand': "sample brand",
                          'voltage': "sample voltage"}

        with patch('builtins.input', side_effect=electronic_app_inputs):
            main.add_new_item()
        self.assertEqual(main.full_inventory, sample_inventory)

        # Test adding general inventory item to the full_inventory
        inventory_inputs = (121, "sample description", "sample rental price",
                            "n", "n")

        sample_inventory[121] = {'product_code': 121,
                          'description': "sample description",
                          'market_price': 24,
                          'rental_price': "sample rental price"}

        with patch('builtins.input', side_effect=inventory_inputs):
            main.add_new_item()
        self.assertEqual(main.full_inventory, sample_inventory)
Beispiel #12
0
    def test_add_new_item(self):
        """ Test the add_new_item function """

        main.full_inventory = {}
        inventory = {
            'product_code': 1,
            'description': 'Dummy Description',
            'market_price': 24,
            'rental_price': 10
        }
        furniture = {
            'product_code': 2,
            'description': 'Dummy Description',
            'market_price': 24,
            'rental_price': 10,
            'material': 'Upholstery',
            'size': 'L'
        }
        electric_appliance = {
            'product_code': 3,
            'description': 'Dummy Description',
            'market_price': 24,
            'rental_price': 10,
            'brand': 'Samsung',
            'voltage': 120
        }

        # Test adding regular inventory item
        input = [1, 'Dummy Description', 10, 'n', 'n']
        with patch('builtins.input', side_effect=input):
            main.add_new_item()
            self.assertEqual(main.full_inventory[1], inventory)

        # Test adding furniture item
        input = [2, 'Dummy Description', 10, 'y', 'Upholstery', 'L']
        with patch('builtins.input', side_effect=input):
            main.add_new_item()
            self.assertEqual(main.full_inventory[2], furniture)

        # Test adding electic appliance  item
        input = [3, 'Dummy Description', 10, 'n', 'y', 'Samsung', 120]
        with patch('builtins.input', side_effect=input):
            main.add_new_item()
            self.assertEqual(main.full_inventory[3], electric_appliance)
    def test_moduletest(self):
        main.FULL_INVENTORY = {}

        inventory_input_params = ['Code4', 'Item4 Test', 4, 'n', 'n' ]
        electric_input_params = ['Code5', 'Item5 Test', 5, 'n', 'y', 'BrandB', 120]
        furniture_input_params = ['Code6', 'Item6 Test', 6, 'y', 'MaterialA', 'S']
        target_inventory ={ 
            'Code4': 
                {
                    'product_code': 'Code4',
                    'description': 'Item4 Test',
                    'market_price' : 'Code4',
                    'rental_price' : 4
                }
            ,
            'Code5': 
                {
                    'product_code': 'Code5',
                    'description': 'Item5 Test',
                    'market_price' : 'Code5',
                    'rental_price' : 5,
                    'brand': 'BrandB',
                    'voltage': 120
                }
            ,
            'Code6': 
                {
                    'product_code': 'Code6',
                    'description': 'Item6 Test',
                    'market_price' : 'Code6',
                    'rental_price' : 6,
                    'material': 'MaterialA',
                    'size': 'S'
                }
        }

        with patch('builtins.input', side_effect=inventory_input_params):
            main.add_new_item()
        with patch('builtins.input', side_effect=electric_input_params):
            main.add_new_item()
        with patch('builtins.input', side_effect=furniture_input_params):
            main.add_new_item()

        self.assertEqual(main.FULL_INVENTORY, target_inventory)
    def test_inventory(self):
        """ Test adding inventory """

        main.full_inventory = {}

        generic_input = [1, 'generic', 10, 'n', 'n']
        furniture_input = [2, 'furniture', 10, 'y', 'Upholstery', 'L']
        electric_input = [3, 'electric', 10, 'n', 'y', 'Samsung', 120]

        final_dict = {
            1: {
                'product_code': 1,
                'description': 'generic',
                'market_price': 24,
                'rental_price': 10
            },
            2: {
                'product_code': 2,
                'description': 'furniture',
                'market_price': 24,
                'rental_price': 10,
                'material': 'Upholstery',
                'size': 'L'
            },
            3: {
                'product_code': 3,
                'description': 'electric',
                'market_price': 24,
                'rental_price': 10,
                'brand': 'Samsung',
                'voltage': 120
            }
        }

        with patch('builtins.input', side_effect=generic_input):
            main.add_new_item()

        with patch('builtins.input', side_effect=furniture_input):
            main.add_new_item()

        with patch('builtins.input', side_effect=electric_input):
            main.add_new_item()

        self.assertEqual(main.full_inventory, final_dict)
 def test_add_new_item(self):
     """Test that new items of the correct type are being added"""
     inv_obj_1 = ['545', 'pan', 13.0, 'n', 'n']
     furn_obj_1 = ['0455', 'couch', 30.0, 'y', 'leather', 'L']
     elec_app_1 = ['786', 'phone charger', 130.0, 'n', 'y', 'apple', 2.9]
     
     #check if new item is added for inventory
     with patch('market_prices.get_latest_price', return_value=42.0):
         with patch('builtins.input', side_effect=inv_obj_1):
             inventory_dict = {}
             main.FULL_INVENTORY = {}
             main.add_new_item()
             inventory_dict['545'] = {'product_code': '545',
                                      'description': 'pan',
                                      'market_price': 42.0,
                                      'rental_price': 13.0}
             self.assertEqual(inventory_dict, main.FULL_INVENTORY)
     
     #check if new item is added for furniture
     with patch('market_prices.get_latest_price', return_value=280.0):
         with patch('builtins.input', side_effect=furn_obj_1):
             furniture_dict = {}
             main.FULL_INVENTORY = {}
             main.add_new_item()
             furniture_dict['0455'] = {'product_code': '0455',
                                     'description': 'couch',
                                     'market_price': 280.0,
                                     'rental_price': 30.0,
                                     'material': 'leather',
                                     'size': 'L'}
             self.assertEqual(furniture_dict, main.FULL_INVENTORY)
     #check if new item is added for electrical appliance
     with patch('market_prices.get_latest_price', return_value=400.0):
         with patch('builtins.input', side_effect=elec_app_1):
             electrical_dict = {}
             main.FULL_INVENTORY = {}
             main.add_new_item()
             electrical_dict['786'] = {'product_code': '786',
                                       'description': 'phone charger',
                                       'market_price': 400.0,
                                       'rental_price': 130.0,
                                       'brand': 'apple',
                                       'voltage': 2.9}
             self.assertEqual(electrical_dict, main.FULL_INVENTORY)
    def test_add_new_item(self):
        """ tests adding new items to the 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())
    def test_integration(self):

        market_price = get_latest_price(44)

        furn_item = (44, 'Test description', 50, 'y', 'leather', 'L')
        elec_item = (22, 'Test description', 50, 'n', 'y', 'John Deere', 200)
        other_item = (99, 'Test description', 50, 'n', 'n')

        menu.FULL_INVENTORY = {}
        with patch('builtins.input', side_effect=furn_item):
            menu.add_new_item()
        with patch('builtins.input', side_effect=elec_item):
            menu.add_new_item()
        with patch('builtins.input', side_effect=other_item):
            menu.add_new_item()

        test_dict = {
            44: {
                'product_code': 44,
                'description': 'Test description',
                'market_price': 24,
                'rental_price': 50,
                'material': 'leather',
                'size': 'L'
            },
            22: {
                'product_code': 22,
                'description': 'Test description',
                'market_price': 24,
                'rental_price': 50,
                'brand': 'John Deere',
                'voltage': 200
            },
            99: {
                'product_code': 99,
                'description': 'Test description',
                'market_price': 24,
                'rental_price': 50
            }
        }

        self.assertEqual(menu.FULL_INVENTORY, test_dict)
    def test_add_new_item(self):
        '''test add_new_item function with user entering in furniture, appliance, and other'''
        with patch('builtins.input',
                   side_effect=('furniture01', 'chair', 39, 'y', 'suede',
                                'L')):
            main.add_new_item()

        with patch('builtins.input',
                   side_effect=('appliance01', 'radio', 15, 'n', 'y', 'top',
                                120)):
            main.add_new_item()

        with patch('builtins.input',
                   side_effect=('other01', 'misc', 54, 'n', 'n')):
            main.add_new_item()

        self.assertEqual(
            main.FULL_INVENTORY, {
                'furniture01': {
                    'product_code': 'furniture01',
                    'description': 'chair',
                    'market_price': 24,
                    'rental_price': 39,
                    'material': 'suede',
                    'size': 'L'
                },
                'appliance01': {
                    'product_code': 'appliance01',
                    'description': 'radio',
                    'market_price': 24,
                    'rental_price': 15,
                    'brand': 'top',
                    'voltage': 120
                },
                'other01': {
                    'product_code': 'other01',
                    'description': 'misc',
                    'market_price': 24,
                    'rental_price': 54
                }
            })
    def test_add_new_item(self):
        '''tests adding new items to the inventory'''
        item_one = ['1', 'Painting', '50', 'n', 'n']
        item_two = ['2', 'Desk', '100', 'y', 'wood', 'L']
        item_three = ['3', 'Washer', '200', 'n', 'y', 'Kenmore', '120']

        with patch('builtins.input', side_effect=item_one):
            main.add_new_item()

        with patch('builtins.input', side_effect=item_two):
            main.add_new_item()

        with patch('builtins.input', side_effect=item_three):
            main.add_new_item()

        test_dict = {
            '1': {
                'product_code': '1',
                'description': 'Painting',
                'market_price': 24,
                'rental_price': '50'
            },
            '2': {
                'product_code': '2',
                'description': 'Desk',
                'market_price': 24,
                'rental_price': '100',
                'material': 'wood',
                'size': 'L'
            },
            '3': {
                'product_code': '3',
                'description': 'Washer',
                'market_price': 24,
                'rental_price': '200',
                'brand': 'Kenmore',
                'voltage': '120'
            }
        }

        self.assertEqual(test_dict, main.return_full_inventory())
Beispiel #20
0
    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()
Beispiel #21
0
    def test_add_new_item(self, mocked_get_latest_price):
        """Test add_new_item function """
        with mock.patch('builtins.input', return_value='n'):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['n']['product_code'], 'n')
            self.assertEqual(main.FULL_INVENTORY['n']['market_price'], 25)
            mocked_get_latest_price.assert_called_once()
        with mock.patch('builtins.input', return_value='y'):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['y']['product_code'], 'y')
            self.assertEqual(main.FULL_INVENTORY['y']['market_price'], 25)
            self.assertEqual(main.FULL_INVENTORY['y']['size'], 'y')
            self.assertEqual(main.FULL_INVENTORY['y']['material'], 'y')

        with mock.patch('builtins.input',
                        side_effect=['1', '2', '3', 'n', 'y', '4', '5']):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['1']['product_code'], '1')
            self.assertEqual(main.FULL_INVENTORY['1']['market_price'], 25)
            self.assertEqual(main.FULL_INVENTORY['1']['brand'], '4')
            self.assertEqual(main.FULL_INVENTORY['1']['voltage'], '5')
    def test_add_new_item(self):
        main.get_latest_price = MagicMock()
        main.get_latest_price.return_value = 24
        # test the electric appliance inventory input
        electric_appliance_inputs = ['001', 'dishwasher', 12, 'n', 'y',
                                     'GE', 120]
        with patch('builtins.input', side_effect=electric_appliance_inputs):
            main.add_new_item()
            # test total number of inventories
            self.assertEqual(len(main.FULL_INVENTORY), 1)
            self.assertEqual(main.FULL_INVENTORY[0].product_code, '001')
            self.assertEqual(main.FULL_INVENTORY[0].description, 'dishwasher')
            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)

        # test the furniture inventory input
        furniture_inputs = ['002', 'sofa', 12, 'y', 'wood', 'M']
        with patch('builtins.input', side_effect=furniture_inputs):
            main.add_new_item()
            # test total number of inventories
            self.assertEqual(len(main.FULL_INVENTORY), 2)
            self.assertEqual(main.FULL_INVENTORY[1].product_code, '002')
            self.assertEqual(main.FULL_INVENTORY[1].description, 'sofa')
            self.assertEqual(main.FULL_INVENTORY[0].market_price, 24)
            self.assertEqual(main.FULL_INVENTORY[1].rental_price, 12)
            self.assertEqual(main.FULL_INVENTORY[1].material, 'wood')
            self.assertEqual(main.FULL_INVENTORY[1].size, 'M')

        # test other inventory input
        inventory_inputs = ['003', 'cloth', 12, 'n', 'n']
        with patch('builtins.input', side_effect=inventory_inputs):
            main.add_new_item()
            # test total number of inventories
            self.assertEqual(len(main.FULL_INVENTORY), 3)
            self.assertEqual(main.FULL_INVENTORY[2].product_code, '003')
            self.assertEqual(main.FULL_INVENTORY[2].description, 'cloth')
            self.assertEqual(main.FULL_INVENTORY[0].market_price, 24)
            self.assertEqual(main.FULL_INVENTORY[2].rental_price, 12)
    def test_add_new_item(self):
        """Test that user can add a new item to inventory"""
        input_item1 = ['1', 'chair', '10', 'y', 'wood', 'S']
        with patch('builtins.input', side_effect=input_item1):
            main.add_new_item()

        input_item2 = ['2', 'toaster', '20', 'n', 'y', 'Ferrari', '200']
        with patch('builtins.input', side_effect=input_item2):
            main.add_new_item()

        input_item3 = ['3', 'paper', '30', 'n', 'n']
        with patch('builtins.input', side_effect=input_item3):
            main.add_new_item()

        test_dictionary = {
            '1': {
                'product_code': '1',
                'description': 'chair',
                'market_price': 24,
                'rental_price': '10',
                'material': 'wood',
                'size': 'S'
            },
            '2': {
                'product_code': '2',
                'description': 'toaster',
                'market_price': 24,
                'rental_price': '20',
                'brand': 'Ferrari',
                'voltage': '200'
            },
            '3': {
                'product_code': '3',
                'description': 'paper',
                'market_price': 24,
                'rental_price': '30'
            }
        }

        self.assertEqual(test_dictionary, main.return_full_inventory())
    def test_addNewItem(self):
        """
		Tests add new item function
		"""
        with mock.patch(
                'builtins.input',
                side_effect=['300', 'shirt', '500', 'y', 'cotton', 'S']):
            add_new_item()
            self.assertEqual(
                FULL_INVENTORY['300'], {
                    'product_code': '300',
                    'description': 'shirt',
                    'market_price': 24,
                    'rental_price': '500',
                    'material': 'cotton',
                    'size': 'S'
                })
        with mock.patch(
                'builtins.input',
                side_effect=['200', 'machine', '500', 'n', 'y', 'ACE', '12']):
            add_new_item()
            self.assertEqual(
                FULL_INVENTORY['200'], {
                    'product_code': '200',
                    'description': 'machine',
                    'market_price': 24,
                    'rental_price': '500',
                    'brand': 'ACE',
                    'voltage': '12'
                })
        with mock.patch('builtins.input',
                        side_effect=['100', 'shirt', '500', 'n', 'n']):
            add_new_item()
            self.assertEqual(
                FULL_INVENTORY['100'], {
                    'product_code': '100',
                    'description': 'shirt',
                    'market_price': 24,
                    'rental_price': '500'
                })
Beispiel #25
0
    def test_add_new_item(self):
        '''Tests the add_new_item function'''

        # User inputs
        test_inventory = ['I123', 'Thingabob', 4.99, 'n', 'n']
        test_furniture = ['C234', 'chair', 39.99, 'y', 'wood', 'X-Large']
        test_elect_app = ['E345', 'refrigerator', 145.99, 'n', 'y', 'GE', 110]

        # Tests adding an inventory item
        with patch('builtins.input', side_effect=test_inventory):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['I123'], TEST_DICT['I123'])

        # Tests adding a furniture item
        with patch('builtins.input', side_effect=test_furniture):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['C234'], TEST_DICT['C234'])

        # Tests adding an electrical appliance item
        with patch('builtins.input', side_effect=test_elect_app):
            main.add_new_item()
            self.assertEqual(main.FULL_INVENTORY['E345'], TEST_DICT['E345'])
    def test_add_new_item(self):
        inventory = ['0', 'desc', '1', 'n', 'n']
        furniture = [17, 'desc', 354, 'y', 'bronze', 'XL']
        electric = [777, 'desc', 999, 'n', 'y', 'MYBRAND', 2]

        with patch('builtins.input', side_effect=inventory):
            add_new_item()

        self.assertEqual(FULL_INVENTORY['0'],  {'product_code': '0', 'description': 'desc',
                                                'market_price': 24, 'rental_price': '1'})

        with patch('builtins.input', side_effect=furniture):
            add_new_item()

        self.assertEqual(FULL_INVENTORY[17], {'product_code': 17, 'description': 'desc',
                                            'market_price': 24, 'rental_price': 354,
                                              'material': 'bronze', 'size': 'XL'})

        with patch('builtins.input', side_effect=electric):
            add_new_item()

        self.assertEqual(FULL_INVENTORY[777], {'product_code': 777, 'description': 'desc',
                                               'market_price': 24, 'rental_price': 999,
                                               'brand': 'MYBRAND', 'voltage': 2})
Beispiel #27
0
    def test_add_items(self):
        item_details1 = [25, 'Stool', 25, 'y', 'Wood', 'M']
        inventory1 = {
            25: {
                'product_code': 25,
                'description': 'Stool',
                'market_price': 24,
                'rental_price': 25,
                'material': 'Wood',
                'size': 'M'
            }
        }

        with patch('builtins.input', side_effect=item_details1):
            main.add_new_item()
        self.assertEqual(main.FULL_INVENTORY, inventory1)

        item_details2 = [17, 'Lamp', 50, 'n', 'y', 'SmartLamps', 425]
        inventory2 = {
            25: {
                'product_code': 25,
                'description': 'Stool',
                'market_price': 24,
                'rental_price': 25,
                'material': 'Wood',
                'size': 'M'
            },
            17: {
                'product_code': 17,
                'description': 'Lamp',
                'market_price': 24,
                'rental_price': 50,
                'brand': 'SmartLamps',
                'voltage': 425
            }
        }

        with patch('builtins.input', side_effect=item_details2):
            main.add_new_item()
        self.assertEqual(main.FULL_INVENTORY, inventory2)

        item_details3 = [32, 'Shoe', 50, 'n', 'n']
        inventory3 = {
            25: {
                'product_code': 25,
                'description': 'Stool',
                'market_price': 24,
                'rental_price': 25,
                'material': 'Wood',
                'size': 'M'
            },
            17: {
                'product_code': 17,
                'description': 'Lamp',
                'market_price': 24,
                'rental_price': 50,
                'brand': 'SmartLamps',
                'voltage': 425
            },
            32: {
                'product_code': 32,
                'description': 'Shoe',
                'market_price': 24,
                'rental_price': 50
            }
        }

        with patch('builtins.input', side_effect=item_details3):
            main.add_new_item()
        self.assertEqual(main.FULL_INVENTORY, inventory3)

        item_dict = {
            'product_code': 32,
            'description': 'Shoe',
            'market_price': 24,
            'rental_price': 50
        }
        with patch('builtins.input', side_effect='32'):
            self.assertEqual(main.item_info(), print(item_dict))
Beispiel #28
0
    def test_add_new_item(self):
        """ Test the various items types cab be added to the inventory object """

        # Different inventory object lists used for testing. Remember to include the yes and
        # no answers for the item type.
        furniture_list = ["2", "Couch", "100", "Y", "leather", "8ft"]
        appliance_list = [
            "25", "Microwave", "10", "N", "Y", "Kitchen-aid", "110"
        ]
        inventory_list = ["450", "item", "5", "N", "N"]

        inventory_dict = {
            "2": {
                "product_code": "2",
                "description": "Couch",
                "market_price": 1500,
                "rental_price": "100",
                "material": "leather",
                "size": "8ft"
            },
            "25": {
                "product_code": "25",
                "description": "Microwave",
                "market_price": 300,
                "rental_price": "10",
                "brand": "Kitchen-aid",
                "voltage": "110"
            },
            "450": {
                "product_code": "450",
                "description": "item",
                "market_price": 235,
                "rental_price": "5"
            }
        }

        # Test adding a furniture object
        # First mock getting a value from market prices then mock the user input
        with patch('inventory_management.market_prices.get_latest_price',
                   return_value=1500):
            with patch('builtins.input', side_effect=furniture_list):
                main.add_new_item()
                # Test for the furniture item in the full inventory dict
                self.assertEqual(inventory_dict.get("2"),
                                 main.FULL_INVENTORY.get("2"))

        # Test adding an appliance object
        with patch('inventory_management.market_prices.get_latest_price',
                   return_value=300):
            with patch('builtins.input', side_effect=appliance_list):
                main.add_new_item()
                # Test for the appliance item in the full inventory dict
                self.assertEqual(inventory_dict.get("25"),
                                 main.FULL_INVENTORY.get("25"))

        # Test adding a generic inventory object
        with patch('inventory_management.market_prices.get_latest_price',
                   return_value=235):
            with patch('builtins.input', side_effect=inventory_list):
                main.add_new_item()
                # Test for all the items (furniture, appliance, and inventory) are in the
                # full inventory dict
                self.assertEqual(inventory_dict, main.FULL_INVENTORY)
 def test_add_new_appliance(self, mock_stdout):
     with patch('builtins.input', self.mock_appliance_inputs):
         main.add_new_item()
         self.assertEqual(main.full_inventory, {"0": {'brand': 'Generic', 'description': 'Desc', 'market_price': 24, 'product_code': '0', 'rental_price': '0', 'voltage': '1'}})
         self.assertEqual(mock_stdout.getvalue(), "New inventory item added\n")
 def test_add_new_furniture(self, mock_stdout):
     with patch('builtins.input', self.mock_furniture_inputs):
         main.add_new_item()
         self.assertEqual(main.full_inventory, {"1": {'description': 'Desc', 'market_price': 24, 'material': 'Wood','product_code': '1', 'rental_price': '0', 'size': 'M'}})
         self.assertEqual(mock_stdout.getvalue(), "New inventory item added\n")