def test_create_menu_when_menu_exists(self, mock_get_location, mock_request_params, mock_get_unpaginated): '''Test the response returned when menu already exists. ''' # Arrange with self.app.app_context(): mock_get_location.return_value = 1 mock_request_params.return_value = (None, None, None, None, None, None, None, None) mock_get_unpaginated.return_value = [ { 'date': datetime.now(), 'meal_period': 'lunch', 'location_id': 1, 'main_meal_id': 1, 'allowed_side': 1, 'allowed_protein': 1, 'side_items': '', 'protein_items': '' }, ] menu_controller = MenuController(self.request_context) # Act result = menu_controller.create_menu() # Assert assert result.status_code == 400 assert result.get_json()['msg'] == "You can't create multiple " \ "menus with same main item on the same day"
def test_create_menu_successful(self, mock_get_location, mock_request_params, mock_get_unpaginated, mock_new_menu, mock_get, mock_get_meal_items): '''Test response returned when the menu is created successfully. ''' # Arrange with self.app.app_context(): mock_get_location.return_value = 1 mock_request_params.return_value = (None, None, None, None, None, None, None, None) mock_get_unpaginated.return_value = None mock_new_menu.return_value = MealItem(meal_type='', name='', image='', location_id=0, created_at=datetime.now(), updated_at=datetime.now(), is_deleted=False, id=1, location={}) mock_get.return_value = MealItem(meal_type='', name='', image='', location_id=0, created_at=datetime.now(), updated_at=datetime.now(), is_deleted=False, id=1) mock_get_meal_items.return_value = [] menu_controller = MenuController(self.request_context) # Act result = menu_controller.create_menu() # Assert assert result.status_code == 201 assert result.get_json()['msg'] == "OK"