Exemple #1
0
 def setUp(self):
     self.logPoint()
     self.mango_lasi3 = Drink("mango lasis", 10, datetime.date(2017, 9,
                                                               12), 12.99,
                              80, "lasi producer ltd", 129.99, False, False)
     self.menu_item_manager = MenuItemManager(
         'C:/Users/user/Desktop/ACIT2515_ASSIGNMENT3-master/test_menu.json')
    def setUp(self):
        """Set up for all the values"""
        self.logPoint()
        self.kashmir_dosa = MenuItemManager("kashmir dosa")
        self.barley_bread = Food("barley bread", 12, datetime.date(2018, 8, 8), 12.99, 149, "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, datetime.date(2017, 9, 12), 12.99, 80, "lasi producer ltd", 129.99,
                            False, False)

        self.undefined_value = None
        self.empty_value = ""
    def setUp(self):
        """Set up for all the values"""
        self.logPoint()

        self.kashmir_dosa = MenuItemManager(
            'D:/OOP/Assignment3/v1.2/test_menu1.json')
        self.barley_bread = Food("barley bread", 12, "2012-02-02", 12.99, 149,
                                 "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, "2012-02-02", 12.99, 80,
                                 "lasi producer ltd", 129.99, False, False)

        self.undefined_value = None
        self.empty_value = ""
    def setUp(self):
        """Set up for all the values"""

        engine = create_engine('sqlite:///test_menu.sqlite')

        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.logPoint()

        self.kashmir_dosa = MenuItemManager('Kashmir Dosa', "test_menu.sqlite")

        self.barley_bread = Food("barley bread", 12, datetime.datetime.now(),
                                 12.99, 149, "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, datetime.datetime.now(),
                                 12.99, 80, "lasi producer ltd", 129.99, False,
                                 False)

        self.undefined_value = None
        self.empty_value = ""
Exemple #5
0
def main():
    barley_bread = Food("barley bread", 12, datetime.date(2018, 8, 8), 12.99,
                        149, "India", "Barley", "small", True)
    mango_lasi = Drink("mango lasis", 10, datetime.date(2017, 9, 12), 7.99, 80,
                       "lasi producer ltd", 129.99, False, False)
    mango_lasi3 = Drink("mango lasis", 10, datetime.date(2017, 9, 12), 12.99,
                        80, "lasi producer ltd", 129.99, False, False)
    print(mango_lasi3.menu_item_description())
    mango_lasi.set_id(2)

    kashmir_dosa = MenuItemManager("kashmir dosa")
    kashmir_dosa.add_menu_item(barley_bread)

    kashmir_dosa.add_menu_item(mango_lasi3)
    kashmir_dosa.update(mango_lasi)
    print_report(kashmir_dosa)

    print(kashmir_dosa.menu_exist(2))
class Testmanager(unittest.TestCase):
    """ Unit tests for menu_item_managerr"""
    @patch('builtins.open', mock_open(read_data=''))
    def setUp(self):
        """Set up for all the values"""
        self.logPoint()

        self.kashmir_dosa = MenuItemManager(
            'D:/OOP/Assignment3/v1.2/test_menu1.json')
        self.barley_bread = Food("barley bread", 12, "2012-02-02", 12.99, 149,
                                 "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, "2012-02-02", 12.99, 80,
                                 "lasi producer ltd", 129.99, False, False)

        self.undefined_value = None
        self.empty_value = ""

    def test_team(self):
        """ 010A: Valid Construction """

        self.logPoint()

        self.assertIsNotNone(self.kashmir_dosa, "Team must be defined")

    def test_add(self):
        """ 020A: Valid Add menu """

        self.logPoint()

        self.assertIsNotNone(self.barley_bread, "Food must be defined")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu has one item")
        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

    def test_add_menu_already_exists(self):
        """ 020C: Invalid Add menu - Menu Already Exists """

        self.logPoint()

        self.assertEqual(len(self.kashmir_dosa.get_all()), 0,
                         "Menu has no item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         " Menu must have 1 item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu must have 1 item")

    def test_remove_menu_item(self):
        """ 030A: Valid remove menu """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_id(), 1)

        self.kashmir_dosa.remove_menu_item(1)
        self.assertEqual(len(self.kashmir_dosa._menu), 0,
                         "Must have no menu item")

    def test_delete_non_existent_menu(self):
        """ 030C: Invalid Delete Menu item - No id existent """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_id(), 1)

        self.kashmir_dosa.remove_menu_item(4)
        self.assertEqual(len(self.kashmir_dosa._menu), 1,
                         "menu must have one items")

    def test_get_by_id(self):
        """ 040A: Valid Get the menu wanted """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_price(), 12.99,
                         "menu price needs to be 12.99")
        self.assertEqual(menu.get_menu_item_no(), 12,
                         "Menu item number needs to be 12")

    def test_menu_exist(self):
        """050A: Valid menu exists"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

        self.assertTrue("needs to be true", self.kashmir_dosa.menu_exist(1))

    def test_get_all(self):
        """060A: Get all the menus"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        list_menus = self.kashmir_dosa.get_all()

        for i in list_menus:
            self.assertEqual(i['menu_item_name'], "barley bread",
                             "needs to be barley bread")

    def get_all_menu_item(self):
        self.logPoint()
        """070A: Get all the menu item"""
        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        self.assertEqual(self.kashmir_dosa.get_all(),
                         "['barley bread', 'mango lasis'] ",
                         "needs to be list of the items")

    def test_update(self):
        """ 080A: Valid Update """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        mango_lasi = Drink("mango lasi", 8, "2017-9-12", 6.99, 80,
                           "lasi producer ltd", 129.99, False, False)

        mango_lasi.set_id(1)

        self.kashmir_dosa.update(mango_lasi)

    def test_get_menu_item_stats(self):

        self.logPoint()
        """090A Check the stats of the menu"""

        mango_lasi = Drink("mango lasi", 8, "2017-9-12", 6.99, 80,
                           "lasi producer ltd", 129.99, False, False)

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)
        self.kashmir_dosa.add_menu_item(mango_lasi)

        stats = self.kashmir_dosa.get_menu_item_stats()

        self.assertEqual(stats.get_total_num_menu_items(), 3)
        self.assertEqual(stats.get_num_foods(), 1)
        self.assertEqual(stats.get_num_drinks(), 2)
        self.assertEqual(stats.get_avg_price_food(), 12.990000)
        self.assertEqual(stats.get_avg_price_drink(), 9.990000)

    def test_path(self):
        """  tests for parameter validation on the filepath parameter """
        pass

    def test_read_menu_from_file(self):
        """ Tests read menu_from_file"""
        pass

    def test_write_menu_to_file(self):
        """ Tests write menu_to_file"""
        pass

    def tearDown(self):
        """ Create a test fixture after each test method is run """

        try:
            os.remove("D:/OOP/Assignment3/v1.2/test_menu1.json")
        except:
            pass

        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))
Exemple #7
0
class Testmanager(unittest.TestCase):
    """ Unit tests for menu_item_managerr"""
    def setUp(self):
        """Set up for all the values"""
        self.logPoint()
        self.kashmir_dosa = MenuItemManager("kashmir dosa")
        self.barley_bread = Food("barley bread", 12, datetime.date(2018, 8, 8),
                                 12.99, 149, "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, datetime.date(2017, 9,
                                                                  12), 12.99,
                                 80, "lasi producer ltd", 129.99, False, False)

        self.undefined_value = None
        self.empty_value = ""

    def test_team(self):
        """ 010A: Valid Construction """

        self.logPoint()

        self.assertIsNotNone(self.kashmir_dosa, "Team must be defined")

    def test_add(self):
        """ 020A: Valid Add menu """

        self.logPoint()

        self.assertIsNotNone(self.barley_bread, "Food must be defined")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu has one item")
        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

    def test_add_undefined(self):
        """020B: invalid add menu"""
        self.logPoint()

        undefined_menu = None
        with self.assertRaisesRegex(ValueError,
                                    'menu_item cannot be undefined'):
            self.kashmir_dosa.add_menu_item(undefined_menu)

    def test_add_menu_already_exists(self):
        """ 020C: Invalid Add menu - Menu Already Exists """

        self.logPoint()

        self.assertEqual(len(self.kashmir_dosa.get_all()), 0,
                         "Menu has no item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         " Menu must have 1 item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu must have 1 item")

    def test_remove_menu_item(self):
        """ 030A: Valid remove menu """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_id(), 1)

        self.kashmir_dosa.remove_menu_item(1)
        self.assertEqual(len(self.kashmir_dosa._menu), 0,
                         "Must have no menu item")

    def test_remove_notint_menu_id(self):
        """ 030B: Invalid id int """

        self.logPoint()
        asdf = "3"
        self.assertRaisesRegex(ValueError, "needs to be int",
                               self.kashmir_dosa.remove_menu_item, asdf)

    def test_remove_invalid_menu_id(self):
        """030C: invalid remove parameter"""
        self.logPoint()

        self.assertRaisesRegex(ValueError, "id cannot be undefined",
                               self.kashmir_dosa.remove_menu_item,
                               self.undefined_value)
        self.assertRaisesRegex(ValueError, "id cannot be empty",
                               self.kashmir_dosa.remove_menu_item,
                               self.empty_value)

    def test_delete_non_existent_menu(self):
        """ 030C: Invalid Delete Menu item - No id existent """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_id(), 1)

        self.kashmir_dosa.remove_menu_item(4)
        self.assertEqual(len(self.kashmir_dosa._menu), 1,
                         "menu must have one items")

    def test_get_by_id(self):
        """ 040A: Valid Get the menu wanted """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.get_price(), 12.99,
                         "menu price needs to be 12.99")
        self.assertEqual(menu.get_menu_item_no(), 12,
                         "Menu item number needs to be 12")

    def test_menu_exist(self):
        """050A: Valid menu exists"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        self.assertEqual(self.kashmir_dosa._next_available_id, 1,
                         "Id must be one")

        self.assertTrue("needs to be true", self.kashmir_dosa.menu_exist(1))

    def test_get_all(self):
        """060A: Get all the menus"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)
        list_menus = self.kashmir_dosa.get_all()

        self.assertEqual(list_menus[0].get_menu_item_name(), "barley bread",
                         "needs to be barley bread")
        self.assertEqual(list_menus[1].get_menu_item_no(), 10,
                         "needs to be 10")

    def get_all_menu_item(self):

        self.logPoint()
        """070A: Get all the menu item"""
        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        self.assertEqual(self.kashmir_dosa.get_all_menu_item(),
                         "['barley bread', 'mango lasis'] ",
                         "needs to be list of the items")

    def test_update(self):
        """ 080A: Valid Update """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        mango_lasi = Drink("mango lasi", 8, datetime.date(2017, 9, 12), 6.99,
                           80, "lasi producer ltd", 129.99, False, False)

        mango_lasi.set_id(2)

        self.kashmir_dosa.update(mango_lasi)

        self.assertEqual(self.kashmir_dosa.get_by_id(2).get_price(), 6.99)

    def test_get_menu_item_stats(self):

        self.logPoint()
        """090A Check the stats of the menu"""

        mango_lasi = Drink("mango lasi", 8, datetime.date(2017, 9, 12), 6.99,
                           80, "lasi producer ltd", 129.99, False, False)

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)
        self.kashmir_dosa.add_menu_item(mango_lasi)

        stats = self.kashmir_dosa.get_menu_item_stats()

        self.assertEqual(stats.get_total_num_menu_items(), 3)
        self.assertEqual(stats.get_num_foods(), 1)
        self.assertEqual(stats.get_num_drinks(), 2)
        self.assertEqual(stats.get_avg_price_food(), 12.990000)
        self.assertEqual(stats.get_avg_price_drink(), 9.990000)

    def tearDown(self):

        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))
from flask import Flask, request
from food import Food
from drink import Drink
from abstract_menu_item import AbstractMenuItem
from menu_item_manager import MenuItemManager
import json
from datetime import datetime

app = Flask(__name__)

menu_item_manager = MenuItemManager('Kashmir Dosa', "menu.sqlite")


# This is where the API methods will go
@app.route('/menu/menu_items', methods=['POST'])
def add_item():
    """ add a menu item """
    content = request.json
    try:
        for item in content:
            if content['type'] == 'food':
                menu_item = Food(
                    content['menu_item_name'], content['menu_item_no'],
                    datetime.strptime(content['date_added'], '%Y-%m-%d'),
                    content['price'], content['calories'],
                    content['cuisine_country'], content['main_ingredient'],
                    content['portion_size'], content['is_vegetarian'])

            elif content['type'] == 'drink':
                menu_item = Drink(
                    content['menu_item_name'], content['menu_item_no'],
class Testfood(unittest.TestCase):
    """ Unit tests for food class """

    def setUp(self):

        self.logPoint()
        self.barley_bread = Food("barley bread", 12, datetime.date(2018, 8, 8), 12.99, 149, "India", "Barley", "small",
                                 True)
        self.menu_item_manager = MenuItemManager('C:/Users/user/Desktop/ACIT2515_ASSIGNMENT3-master/test_menu.json')

    def test_food_valid(self):
        """ 010A: Valid values for constructor """
        self.logPoint()
        self.assertIsNotNone(self.barley_bread)


    def test_menu_item_description(self):
        """020A:Checks the item description"""
        self.logPoint()
        self.assertEqual(self.barley_bread.menu_item_description(), "Food item barley bread with menu index of 12 added on 2018-08-08 with the price of 12.99, containing 149 calories has a country origin of India and its main ingredient is Barley . Portion size is small and the food is vegetarian", "printed valid description" )

    def test_get_portion_size(self):
        """030A: Checks the test portion size"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_portion_size(),"small", "needs to be small")

    def test_get_main_ingredient(self):
        """040A: Check the main ingredient"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_main_ingredient(), "Barley", "needs to be Barley")

    def test_get_cuisine_country(self):
        """050A: Checks the cuisine country"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_cuisine_country(), "India", "needs to be india")

    def test_get_menu_item_name(self):
        """060A: checks the menu item name"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_menu_item_name(), "barley bread", "needs to be barley bread")

    def test_get_menu_item_no(self):
        """070A: Checks the menu item number"""
        self.logPoint()
        self.assertEqual(self.barley_bread. get_menu_item_no(), 12, "needs to be 12")

    def test_get_date_added(self):
        """080A: Checks the date added"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_date_added(), datetime.date(2018, 8, 8), "needs to be 2018,8,8")

    def test_get_price(self):
        """090A: Checks the price"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_price(), 12.99, "needs to be 12.99")

    def test_get_type(self):
        """100A: Checks the type of the menu"""
        self.logPoint()
        self.assertEqual(self.barley_bread.get_type(), "food", "needs to be drink")

    def test_to_dict(self):
        """using filepath and ensure dict is working well"""
        food_dict = self.menu_item_manager.get_all_by_type('food')

        food_menu = self.menu_item_manager.get_by_id(2)

        food_dict2 = food_menu.to_dict()

        self.logPoint()

        self.assertEqual(food_dict[0]['menu_item_name'], food_dict2['menu_item_name'], "needs to be same")
        self.assertEqual(food_dict[0]['menu_item_no'], food_dict2['menu_item_no'], "needs to be same")
        self.assertEqual(food_dict[0]['date_added'], food_dict2['date_added'], "needs to be same")
        self.assertEqual(food_dict[0]['price'], food_dict2['price'], "needs to be same")
        self.assertEqual(food_dict[0]['calories'], food_dict2['calories'], "needs to be same")
        self.assertEqual(food_dict[0]['cuisine_country'], food_dict2['cuisine_country'], "needs to be same")
        self.assertEqual(food_dict[0]['main_ingredient'], food_dict2['main_ingredient'], "needs to be same")
        self.assertEqual(food_dict[0]['portion_size'], food_dict2['portion_size'], "needs to be same")
        self.assertEqual(food_dict[0]['is_vegetarian'], food_dict2['is_vegetarian'], "needs to be same")

    def tearDown(self):

        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))
    def setUp(self):

        self.logPoint()
        self.barley_bread = Food("barley bread", 12, datetime.date(2018, 8, 8), 12.99, 149, "India", "Barley", "small",
                                 True)
        self.menu_item_manager = MenuItemManager('C:/Users/user/Desktop/ACIT2515_ASSIGNMENT3-master/test_menu.json')
Exemple #11
0
class TestDrink(unittest.TestCase):
    """ Unit tests for drink  """
    def setUp(self):
        self.logPoint()
        self.mango_lasi3 = Drink("mango lasis", 10, datetime.date(2017, 9,
                                                                  12), 12.99,
                                 80, "lasi producer ltd", 129.99, False, False)
        self.menu_item_manager = MenuItemManager(
            'C:/Users/user/Desktop/ACIT2515_ASSIGNMENT3-master/test_menu.json')

    def test_drink_valid(self):
        """ 010A: Valid values for constructor """
        self.logPoint()
        self.assertIsNotNone(self.mango_lasi3)

    def test_menu_item_description(self):
        """ 020A: Check that it does not return wrong description"""
        self.logPoint()
        self.assertNotEqual(
            self.mango_lasi3.menu_item_description(),
            "mango lasis is a fizzy cold drink item with menu index 10 added on 2017-09-12 with the price of 12.99, containing 80 calories made by lasi producer ltd and is 129.99 ml",
            "printed valid description")

    def test_get_manufacturer(self):
        """030A: Return the manufacturer name"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_manufacturer(),
                         "lasi producer ltd", "needs to be lasi producer ltd")

    def test_get_size(self):
        """040A: checks the size of the drink"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_size(), 129.99,
                         "needs to be 129.99")

    def test_get_menu_item_name(self):
        """050A: checks the menu item name"""

        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_menu_item_name(), "mango lasis",
                         "needs to be mango lasis")

    def test_get_menu_item_no(self):
        """060A: checks the menu item number"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_menu_item_no(), 10,
                         "needs to be 10")

    def test_get_date_added(self):
        """070A: checks the added date"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_date_added(),
                         datetime.date(2017, 9, 12), "needs to be 2017, 9 ,12")

    def test_get_price(self):
        """080A: checks get price"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_price(), 12.99,
                         "needs to be 12.99")

    def test_get_type(self):
        """090A: Checks the type of the menu"""
        self.logPoint()
        self.assertEqual(self.mango_lasi3.get_type(), "drink",
                         "needs to be drink")

    def test_to_dict(self):
        """using filepath and ensure dict is working well"""
        drink_dict = self.menu_item_manager.get_all_by_type('drink')

        drink_menu = self.menu_item_manager.get_by_id(1)

        drink_dict2 = drink_menu.to_dict()

        self.logPoint()

        self.assertEqual(drink_dict[0]['menu_item_name'],
                         drink_dict2['menu_item_name'], "needs to be same")
        self.assertEqual(drink_dict[0]['menu_item_no'],
                         drink_dict2['menu_item_no'], "needs to be same")
        self.assertEqual(drink_dict[0]['date_added'],
                         drink_dict2['date_added'], "needs to be same")
        self.assertEqual(drink_dict[0]['price'], drink_dict2['price'],
                         "needs to be same")
        self.assertEqual(drink_dict[0]['calories'], drink_dict2['calories'],
                         "needs to be same")
        self.assertEqual(drink_dict[0]['manufacturer'],
                         drink_dict2['manufacturer'], "needs to be same")
        self.assertEqual(drink_dict[0]['size'], drink_dict2['size'],
                         "needs to be same")
        self.assertEqual(drink_dict[0]['is_fizzy'], drink_dict2['is_fizzy'],
                         "needs to be same")
        self.assertEqual(drink_dict[0]['is_hot'], drink_dict2['is_hot'],
                         "needs to be same")

    def tearDown(self):
        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))
class Testmanager(unittest.TestCase):
    """ Unit tests for menu_item_managerr"""
    def setUp(self):
        """Set up for all the values"""

        engine = create_engine('sqlite:///test_menu.sqlite')

        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.logPoint()

        self.kashmir_dosa = MenuItemManager('Kashmir Dosa', "test_menu.sqlite")

        self.barley_bread = Food("barley bread", 12, datetime.datetime.now(),
                                 12.99, 149, "India", "Barley", "small", True)

        self.mango_lasi3 = Drink("mango lasis", 10, datetime.datetime.now(),
                                 12.99, 80, "lasi producer ltd", 129.99, False,
                                 False)

        self.undefined_value = None
        self.empty_value = ""

    def test_team(self):
        """ 010A: Valid Construction """
        self.assertIsNotNone(self.kashmir_dosa, "Team must be defined")

    def test_add(self):
        """ 020A: Valid Add menu """

        self.assertIsNotNone(self.barley_bread, "Food must be defined")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu has one item")

    def test_add_menu_already_exists(self):
        """ 020C: Invalid Add menu - Menu Already Exists """

        self.logPoint()

        self.assertEqual(len(self.kashmir_dosa.get_all()), 0,
                         "Menu has no item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         " Menu must have 1 item")

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "Menu must have 1 item")

    def test_remove_menu_item(self):
        """ 030A: Valid remove menu """

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.assertEqual(self.kashmir_dosa._restaurant_name, "Kashmir Dosa",
                         "Id must be one")

        self.kashmir_dosa.remove_menu_item(1)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 0,
                         "Must have no menu item")

    def test_delete_non_existent_menu(self):
        """ 030C: Invalid Delete Menu item - No id existent """

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

        self.assertEqual(menu.id, 1)

        self.assertRaisesRegex(ValueError, "id does not exist.",
                               self.kashmir_dosa.remove_menu_item, 4)
        self.assertEqual(len(self.kashmir_dosa.get_all()), 1,
                         "menu must have one items")

    def test_get_by_id(self):
        """ 040A: Valid Get the menu wanted """

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        menu = self.kashmir_dosa.get_by_id(1)

    def test_menu_exist(self):
        """050A: Valid menu exists"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        self.assertTrue("needs to be true", self.kashmir_dosa.menu_exist(1))

    def test_get_all(self):
        """060A: Get all the menus"""
        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)

        list_menus = self.kashmir_dosa.get_all()

        self.assertEqual(list_menus[0], "barley bread",
                         "needs to be barley bread")

    def get_all_menu_item(self):
        self.logPoint()
        """070A: Get all the menu item"""
        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        self.assertEqual(self.kashmir_dosa.get_all(),
                         "['barley bread', 'mango lasis'] ",
                         "needs to be list of the items")

    def test_update(self):
        """ 080A: Valid Update """

        self.logPoint()

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)

        mango_lasi = Drink("mango lasi5", 8, datetime.datetime.now(), 6.99, 80,
                           "lasi producer ltd", 129.99, False, False)

        self.kashmir_dosa.update(2, mango_lasi)

        self.assertEqual(self.kashmir_dosa.get_all()[1], "mango lasi5")

    def test_get_menu_item_stats(self):

        self.logPoint()
        """090A Check the stats of the menu"""

        mango_lasi = Drink("mango lasi", 8, datetime.datetime.now(), 6.99, 80,
                           "lasi producer ltd", 129.99, False, False)

        self.kashmir_dosa.add_menu_item(self.barley_bread)
        self.kashmir_dosa.add_menu_item(self.mango_lasi3)
        self.kashmir_dosa.add_menu_item(mango_lasi)

        stats = self.kashmir_dosa.get_menu_item_stats()
        stats_dict = stats.to_dict()
        self.assertEqual(stats_dict['_total_num_menu_items'], 3)

    def tearDown(self):
        """ Create a test fixture after each test method is run """
        os.remove("test_menu.sqlite")
        self.logPoint()

    def logPoint(self):
        currentTest = self.id().split('.')[-1]
        callingFunction = inspect.stack()[1][3]
        print('in %s - %s()' % (currentTest, callingFunction))
from flask import Flask, request
from food import Food
from drink import Drink
from abstract_menu_item import AbstractMenuItem
from menu_item_manager import MenuItemManager
import json
import os

app = Flask(__name__)

menu_item_manager = MenuItemManager('D:/OOP/Assignment3/v1.2/test_menu.json')


# This is where the API methods will go
@app.route('/menu/menu_items', methods=['POST'])
def add_item():
    """ add a menu item """
    content = request.json
    try:
        for item in content:
            if content['type'] == 'food':
                menu_item = Food(
                    content['menu_item_name'], content['menu_item_no'],
                    (content['date_added']), content['price'],
                    content['calories'], content['cuisine_country'],
                    content['main_ingredient'], content['portion_size'],
                    content['is_vegetarian'])

            elif content['type'] == 'drink':
                menu_item = Drink(content['menu_item_name'],
                                  content['menu_item_no'],