Exemplo n.º 1
0
def test_new_item_electric_app(monkeypatch, mocker):
    """Tests adding a new item of type ElectricAppliances"""
    product_code = 100
    description = 'Oven'
    market_price = 388
    rental_price = 50
    brand = 'Samsung'
    voltage = '230'
    user_input = [
        voltage, brand, 'y', 'n', rental_price, description, product_code
    ]

    with captured_output() as out:
        mock_electric_appliances = \
            mocker.patch.object(ElectricAppliances, 'return_as_dictionary')
        mock_price = mocker.patch('inventory_management.market_prices.' +
                                  'get_latest_price',
                                  return_value=market_price)
        monkeypatch.setattr('builtins.input', lambda x: user_input.pop())

        add_new_item()

        mock_electric_appliances.assert_called_once()
        mock_price.assert_called_once_with(product_code)

        output = out.getvalue()
    assert 'New inventory item added' in output
    assert product_code in FULL_INVENTORY

    print(FULL_INVENTORY)
Exemplo n.º 2
0
    def test_add_new_item_furniture(self):
        """
        Tests main.add_new_item with simulated user input by populating
        FULL_INVENTORY with a sample product and verifying that product is stored
        with the expected keys and values.
        """

        main.FULL_INVENTORY = {}

        inputs = (user_in for user_in in [123, 'Desk', 125, 'y', 'wood', 'l'])

        def mock_input(prompt):
            return next(inputs)

        with patch('builtins.input', mock_input):
            main.add_new_item()

        test_dict = {
            'product_code': 123,
            'description': 'Desk',
            'market_price': 24,
            'rental_price': 125,
            'material': 'wood',
            'size': 'l'
        }

        self.assertEqual(test_dict, main.FULL_INVENTORY[123])
Exemplo n.º 3
0
def test_new_item_furniture(monkeypatch, mocker):
    """Tests adding a new item of type Furniture"""
    product_code = 100
    description = 'Chair'
    market_price = 388
    rental_price = 50
    material = 'Leather'
    size = 'L'
    user_input = [size, material, 'y', rental_price, description, product_code]

    with captured_output() as out:
        mock_furniture = mocker.patch.object(Furniture, 'return_as_dictionary')
        mock_price = mocker.patch('inventory_management.market_prices.' +
                                  'get_latest_price',
                                  return_value=market_price)
        monkeypatch.setattr('builtins.input', lambda x: user_input.pop())

        add_new_item()

        mock_furniture.assert_called_once()
        mock_price.assert_called_once_with(product_code)

        output = out.getvalue()
    assert 'New inventory item added' in output
    assert product_code in FULL_INVENTORY

    print(FULL_INVENTORY)
    def test_item_info(self):
        mock_input = [
            12, "test_description", 15, 'n', 'y', "test_brand", '34kw'
        ]

        with unittest.mock.patch('builtins.input', side_effect=mock_input):
            main.add_new_item()
            self.assertIn(12, main.full_inventory)
            new_dict = main.full_inventory[12]
            self.assertEqual("test_description", new_dict['description'])
            self.assertEqual(15, new_dict['rental_price'])
            self.assertEqual("test_brand", new_dict['brand'])
            self.assertEqual('34kw', new_dict['voltage'])

        with unittest.mock.patch('builtins.input', side_effect=mock_input):

            main.item_info()

            test2 = {
                'product_code': 12,
                'description': 'test_description',
                'market_price': 24,
                'rental_price': 15,
                'brand': 'test_brand',
                'voltage': '34kw'
            }
Exemplo n.º 5
0
 def test_main_add_new_item_basic(self, mock_input, mock_latest_price):
     """Tests the add_new_item function in main.py for general inventory."""
     with patch('main.inventory_class.Inventory') as mock_inventory:
         mock_inventory.return_as_dictionary = MagicMock(return_value=0)
         mock_input.side_effect = ['GI-1', 'Fake Plant', 50., 'n', 'n']
         main.add_new_item()
         mock_inventory.assert_called_with('GI-1', 'Fake Plant', 200., 50.)
Exemplo n.º 6
0
 def test_main_add_new_item_appliance(self, mock_input, mock_latest_price):
     """Tests the add_new_item function in main.py for an electric appliance."""
     with patch('main.electric_appliances_class.ElectricAppliances') as mock_inventory:
         mock_inventory.return_as_dictionary = MagicMock(return_value=0)
         mock_input.side_effect = ['EA-2', 'Dishwasher', 100., 'n', 'y', 'Maytag', '240']
         main.add_new_item()
         mock_inventory.assert_called_with('Maytag', '240', 'EA-2', 'Dishwasher', 450., 100.)
Exemplo n.º 7
0
 def test_main_add_new_item_furniture(self, mock_input, mock_latest_price):
     """Tests the add_new_item function in main.py for furniture."""
     with patch('main.furniture_class.Furniture') as mock_inventory:
         mock_inventory.return_as_dictionary = MagicMock(return_value=0)
         mock_input.side_effect = ['F-1', 'Table', 75., 'y', 'Wood', 'L']
         main.add_new_item()
         mock_inventory.assert_called_with('Wood', 'L', 'F-1', 'Table', 150., 75.)
Exemplo n.º 8
0
 def test_add_new_item_NA(self, mock_get_input):
     mock_get_input.side_effect = [110, 'item 110 desc', 100, 'n', 'n']
     add_new_item()
     self.assertTrue(110 in main.FULL_INVENTORY)
     self.assertFalse(102 in main.FULL_INVENTORY)
     self.assertTrue(
         main.FULL_INVENTORY[110]['description'] == 'item 110 desc')
Exemplo n.º 9
0
 def test_add_new_item_furniture(self, mock_get_input):
     mock_get_input.side_effect = [
         "C777", "reclining couch", 20.00, "y", "leather", "M", ""
     ]
     add_new_item()
     self.assertTrue(20.00 in main.FULL_INVENTORY)
     self.assertFalse(30.00 in main.FULL_INVENTORY)
     self.assertTrue(
         main.FULL_INVENTORY["C777"]['description'] == 'reclining couch')
Exemplo n.º 10
0
 def test_add_new_item_electric_appliances(self, mock_get_input):
     mock_get_input.side_effect = [
         "C555", "electric stove", 300.00, "n", "y", "Kenmore", "150 V", ""
     ]
     add_new_item()
     self.assertTrue(20.00 in main.FULL_INVENTORY)
     self.assertFalse(30.00 in main.FULL_INVENTORY)
     self.assertTrue(
         main.FULL_INVENTORY["C555"]['description'] == 'electric stove')
Exemplo n.º 11
0
 def test_item_info(self, mock_get_input):
     mock_get_input.side_effect = [
         "C555", "electric stove", 300.00, "n", "y", "Kenmore", "150 V", ""
     ]
     add_new_item()
     mock_get_input.side_effect = ["C555"]
     item_output = item_info()
     self.assertTrue(item_output.startswith('product_code: C555'))
     self.assertIn('electric stove', item_output)
Exemplo n.º 12
0
 def test_item_info(self, mock_get_input):
     mock_get_input.side_effect = [
         101, 'item 101 desc', 100, 'y', 'item 101 matl', 'S', ""
     ]
     add_new_item()
     mock_get_input.side_effect = [101]
     item_output = item_info()
     self.assertTrue(item_output.startswith('product_code:101'))
     self.assertIn('item 101 desc', item_output)
Exemplo n.º 13
0
 def test_add_new_item_electrical(self, mock_get_input):
     mock_get_input.side_effect = [
         105, 'item 105 desc', 100, 'n', 'y', 'item 101 brand', 120, ""
     ]
     add_new_item()
     self.assertTrue(105 in main.FULL_INVENTORY)
     self.assertFalse(102 in main.FULL_INVENTORY)
     self.assertTrue(
         main.FULL_INVENTORY[105]['description'] == 'item 105 desc')
Exemplo n.º 14
0
 def test_add_new_item_furniture(self, mock_get_input):
     mock_get_input.side_effect = [
         101, 'item 101 desc', 100, 'y', 'item 101 matl', 'S', ""
     ]
     add_new_item()
     self.assertTrue(101 in main.FULL_INVENTORY)
     self.assertFalse(102 in main.FULL_INVENTORY)
     self.assertTrue(
         main.FULL_INVENTORY[101]['description'] == 'item 101 desc')
Exemplo n.º 15
0
    def test_item_info(self):
        """Tests item info"""
        furniture_input = ('01', 'Couch', 100, 'y', 'leather', 'M')
        with patch('builtins.input', side_effect=furniture_input):
            add_new_item()

        with patch('builtins.input', side_effect=['01']):
            self.assertEqual(item_info(), None)

        with patch('builtins.input', side_effect=['02']):
            self.assertEqual(item_info(), None)
Exemplo n.º 16
0
 def test_item_info(self):
     main.FULL_INVENTORY.clear()
     with patch('builtins.input',
                side_effect=[
                    '123', 'RiceCooker', '5.99', 'n', 'y', 'GE', '220'
                ]):
         main.add_new_item()
     with patch('builtins.input', side_effect=['123']):
         self.assertEqual(main.item_info(), True)
     with patch('builtins.input', side_effect=['456']):
         self.assertEqual(main.item_info(), False)
    def test_add_new_item(self):

        mock_input = [
            2, "test_description", 15, 'n', 'y', "test_brand", '34kw'
        ]

        with unittest.mock.patch('builtins.input', side_effect=mock_input):
            main.add_new_item()
            self.assertIn(2, main.full_inventory)
            new_dict = main.full_inventory[2]
            self.assertEqual("test_description", new_dict['description'])
            self.assertEqual(15, new_dict['rental_price'])
            self.assertEqual("test_brand", new_dict['brand'])
            self.assertEqual('34kw', new_dict['voltage'])
 def test_addinv(self):
     input_inventory = ('789', 'test', 5, 'n', 'n')
     expected_item_dic = {
         '789': {
             'description': 'test',
             'market_price': 24,  # mkt price is static
             'item_code': '789',
             'rental_price': 5
         }
     }
     with patch('builtins.input', side_effect=input_inventory):
         main.FULL_INVENTORY = {}
         main.add_new_item()
         self.assertDictEqual(main.FULL_INVENTORY['789'],
                              expected_item_dic['789'])
Exemplo n.º 19
0
 def test_add_new_furniture_item(self):
     properties = {
         "product_code": "25",
         "description": "Dishwasher",
         "market_price": 200.00,
         "rental_price": 12.00,
         "material": "Cherry",
         "size": 13.2,
         "is_furniture": "y"
     }
     item_count = len(management.FULL_INVENTORY)
     main.add_new_item(properties)
     self.assertEqual(item_count + 1, len(management.FULL_INVENTORY),
                      "New furniture item not added")
     result = management.get_item(properties["product_code"])
     self.assertIsNotNone(result, "New furniture item now found")
Exemplo n.º 20
0
 def test_add_new_item_furniture(self):
     text_trap = io.StringIO()
     sys.stdout = text_trap
     item_dict = {}
     item_dict["item_code"] = "1"
     item_dict["item_description"] = "a"
     item_dict["item_rental_price"] = "1.0"
     item_dict["item_price"] = "1.0"
     item_dict["item_material"] = "a"
     item_dict["size"] = "S"
     item_dict["style"] = "furniture"
     user_input = ["1", "a", "1.0", "y", "a", "S"]
     f_inventory = {}
     f = Furniture(**item_dict)
     f_inventory = {}
     with patch('builtins.input', side_effect=user_input):
         f_inventory = add_new_item(f_inventory)
     new_dict = f_inventory["1"]
     f = Furniture(**item_dict)
     new_dict1 = f.return_as_dictionary()
     self.assertEqual(new_dict["product_code"], new_dict1["product_code"])
     self.assertEqual(new_dict["description"], new_dict1["description"])
     self.assertEqual(new_dict["rental_price"], new_dict1["rental_price"])
     self.assertEqual(new_dict["material"], new_dict1["material"])
     self.assertEqual(new_dict["size"], new_dict1["size"])
     sys.stdout = sys.__stdout__
 def test_addapp(self):
     input_app = ('456', 'foot masseuse', 50, 'n', 'y', 'Costco', 120)
     expected_item_dic = {
         '456': {
             'description': 'foot masseuse',
             'market_price': 24,  # mkt price is static
             'item_code': '456',
             'rental_price': 50,
             'brand': 'Costco',
             'voltage': 120
         }
     }
     with patch('builtins.input', side_effect=input_app):
         main.FULL_INVENTORY = {}
         main.add_new_item()
         self.assertDictEqual(main.FULL_INVENTORY['456'],
                              expected_item_dic['456'])
 def test_addfurn(self):
     input_furniture = ('123', 'bench', 150, 'y', 'wood', 'L')
     expected_item_dic = {
         '123': {
             'description': 'bench',
             'market_price': 24,  # mkt price is static
             'item_code': '123',
             'rental_price': 150,
             'material': 'wood',
             'size': 'L'
         }
     }
     with patch('builtins.input', side_effect=input_furniture):
         main.FULL_INVENTORY = {}
         main.add_new_item()
         self.assertDictEqual(main.FULL_INVENTORY['123'],
                              expected_item_dic['123'])
Exemplo n.º 23
0
 def add_new_item_furniture(self,f_inventory):
     text_trap = io.StringIO()
     sys.stdout = text_trap
     user_input = ["1", "a", "1.0", "y", "a", "S"]
     with patch('builtins.input', side_effect=user_input):
         f_inventory = add_new_item(f_inventory)
     sys.stdout = sys.__stdout__
     return f_inventory
Exemplo n.º 24
0
    def test_item_info(self):
        """ Verify that item_info function properly calls existing items """
        example_item = ('45', 'lamp', 10, 'n', 'n', 'n')
        example_string = 'product_code:45\n'\
                         'description:lamp\n'\
                         'market_price:24\n'\
                         'rental_price:10\m'

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

        with patch('builtins.input', side_effect=('45', )):
            self.assertEqual(item_info(), print(example_string))
        """ Verify that item_info function properly identifies non-existing items """
        example_failed_string = 'Item not found in inventory'

        with patch('builtins.input', side_effect=('1000', )):
            self.assertEqual(item_info(), print(example_failed_string))
 def test_dict_main(self, add_new_item):
     '''
     Testing adding a new item inside main.
     '''
     dict_inv = {'product_code': '123',
                 'description': 'Testing',
                 'market_price': '123.45',
                 'rental_price': '12.34'}
     self.assertEqual(add_new_item(), dict_inv)
Exemplo n.º 26
0
    def test_item_info(self):
        """Test item info """
        test_data = ['1', 'dining', '50', 'y', 'glass', 'L']
        with patch('builtins.input', side_effect=test_data):
            main.add_new_item()
            print(main.FULL_INVENTORY)
        test_item_code = 1
        with patch('builtins.input', side_effect='2'):
            actual_output = main.item_info()
            print("nub")
            print(actual_output)
        expected_output = '''product_code:1
description:dining
market_price:24
rental_price:50
material:glass
size:L'''
        self.assertNotEqual(actual_output, expected_output)
 def test_input_add(self):
     test_dict = {}
     test_dict_main = self.test_dict_main
     text_trap = io.StringIO()
     sys.stdout = text_trap
     user_input = ['123', 'Testing', '123.45', '12.34', 'N', 'N']
     with patch('builtins.input', side_effect=user_input):
         test_dict = add_new_item()
     sys.stdout = sys.__stdout__
     return test_dict
Exemplo n.º 28
0
 def test_menu_add(self):
     '''
     Here we test injecting a value of 1 in the menu
     '''
     while True:
         try:
             with patch('builtins.input', side_effect='1'):
                 self.assertEqual(main_menu(), main.add_new_item())
         except StopIteration as error_code:
             return error_code
Exemplo n.º 29
0
    def test_new_item_inventory(self, mock_inventory, mock_price):
        """Tests adding a new item of type Inventory"""
        product_code = 100
        description = 'Chair'
        market_price = 388
        rental_price = 50
        user_input = [product_code, description, rental_price, 'n', 'n']

        with captured_output() as out:
            with patch('builtins.input', side_effect=user_input):

                add_new_item()
                mock_price.assert_called_once_with(product_code)
                mock_inventory.assert_called_once_with(product_code,
                                                       description,
                                                       market_price,
                                                       rental_price)
                output = out.getvalue()
                self.assertIn("New inventory item added", output)
                self.assertIn(product_code, FULL_INVENTORY)
Exemplo n.º 30
0
    def test_add_new_item(self):
        """ Tests main.add_new_item with simulated user input. """

        main.FULL_INVENTORY = {}

        inputs = (user_in for user_in in [999, 'Vase', 1400, 'n', 'n'])

        def mock_input(prompt):
            return next(inputs)

        with patch('builtins.input', mock_input):
            main.add_new_item()

        test_dict = {
            'product_code': 999,
            'description': 'Vase',
            'market_price': 24,
            'rental_price': 1400
        }

        self.assertEqual(test_dict, main.FULL_INVENTORY[999])