Пример #1
0
 def test_do_menu(self, mock_main_menu):
     """Test that the do_menu logic prints as expected."""
     menu = MainMenu()
     mock_main_menu.return_value = lambda: None
     output, result = capture_output(lambda: menu.do_menu(False))
     self.assertEqual(output, "{}\n" "Press Enter to continue...........")
     self.assertIsNone(result)
Пример #2
0
 def test_item_info_found(self):
     """Test item_info() when input exists in inventory"""
     inventory = {"item_1": {"k1": "v1", "k2": "v2"}}
     menu = MainMenu(inventory)
     output, result = capture_output(menu.item_info)
     self.assertEqual(output, "Enter item code: k1:v1\nk2:v2\n")
     self.assertIsNone(result)
Пример #3
0
 def test_add_new_item_inventory(self):
     """Test that we can add new Inventory"""
     menu = MainMenu()
     capture_output(menu.add_new_item)
     expected = Inventory("item-code", "item-desc", MainTests.MOCK_PRICE,
                          "rental-price").return_as_dictionary()
     self.assertEqual(menu.inventory, {"item-code": expected})
Пример #4
0
 def test_item_info_not_found(self):
     """Test item_info() when input does not exist in inventory"""
     inventory = {"item_1": {"k1": "v1", "k2": "v2"}}
     menu = MainMenu(inventory)
     result = capture_output(menu.item_info)
     self.assertEqual(result,
                      "Enter item code: Item not found in inventory\n")
Пример #5
0
 def test_add_new_item_furniture(self):
     """Test can add new Furniture"""
     menu = MainMenu()
     capture_output(menu.add_new_item)
     expected = Furniture("item-code", "item-desc", MainTests.MOCK_PRICE,
                          "rental-price", "material",
                          "L").return_as_dictionary()
     self.assertEqual(menu.inventory, {"item-code": expected})
Пример #6
0
 def test_add_new_item_electrical(self):
     """Test can add new ElectricalAppliances"""
     menu = MainMenu()
     capture_output(menu.add_new_item)
     expected = ElectricAppliances("item-code", "item-desc",
                                   MainTests.MOCK_PRICE, "rental-price",
                                   "brand", "volt").return_as_dictionary()
     self.assertEqual(menu.inventory, {"item-code": expected})
Пример #7
0
 def test_main_menu(self):
     """Test that the main menu works as expected."""
     menu = MainMenu()
     output, result = capture_output(menu.main_menu)
     self.assertEqual(
         output, ("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" + ">"))
     self.assertEqual(result, menu.exit_program)
    def test_integration(self):
        """Integration Test for Inventory Management"""
        # Redirect stdout just so menu isn't displayed while testing
        old_stdout = sys.stdout
        sys.stdout = io.StringIO()

        inventory = dict()
        with self.assertRaises(SystemExit):
            MainMenu(inventory).do_menu()

        expected = {
            "code1": Furniture("code1", "desc1", self.MOCK_PRICE,
                               "price1", "mat1", "XL").return_as_dictionary(),
            "code2": ElectricAppliances("code2", "desc2", self.MOCK_PRICE,
                                        "price2", "brand2",
                                        "volt2").return_as_dictionary(),
            "code3": Inventory("code3", "desc3", self.MOCK_PRICE,
                               "price3").return_as_dictionary()}
        self.assertEqual(expected, inventory)
        sys.stdout = old_stdout