def test_list_menus_range_ok_response( self, mock_menu_controller_pagination_meta, mock_meal_item_repo_get, mock_menu_repo_get_range_paginated_options, mock_meal_periods_has_value, mock_auth_get_location): '''Test list_menus_range OK response. ''' # Arrange with self.app.app_context(): mock_auth_get_location.return_value = 1 mock_meal_periods_has_value.return_value = True mock_menu = Menu(date=datetime.now(), meal_period='', location_id=1, main_meal_id=1, allowed_side=1, allowed_protein=1, side_items='1,2', protein_items='1,2', vendor_engagement_id=1, created_at=datetime.now(), updated_at=datetime.now()) mock_meal_item = MealItem(id=1, meal_type=1, name='', image='', location_id=1, created_at=datetime.now(), updated_at=datetime.now()) mock_menu_repo_get_range_paginated_options.return_value.items = [ mock_menu, ] mock_meal_item_repo_get.return_value = mock_meal_item mock_period_start_date = '2019-01-01' mock_period_end_date = '2019-02-28' mock_menu_controller_pagination_meta.return_value = { 'total_rows': 1, 'total_pages': 1, 'current_page': 1, 'next_page': False, 'prev_page': False } menu_controller = MenuController(self.request_context) # Act result = menu_controller.list_menus_range('lunch', mock_period_start_date, mock_period_end_date) # Assert assert result.status_code == 200 assert result.get_json()['msg'] == 'OK'
def test_list_menus_range_start_date_gte_end_date( self, mock_meal_periods_has_value, mock_auth_get_location): '''Test list_menu_ranges response when the start date is gte end date. ''' # Arrange with self.app.app_context(): mock_meal_periods_has_value.return_value = True mock_auth_get_location.return_value = 1 mock_meal_period = 'lunch' mock_period_start = '2019-01-28' mock_period_end = '2019-01-01' menu_controller = MenuController(self.request_context) # Act result = menu_controller.list_menus_range(mock_meal_period, mock_period_start, mock_period_end) # Assert assert result.status_code == 400 assert result.get_json()['msg'] == 'Provide valid date ' \ 'range. start_date cannot be greater than end_date'
def test_list_menus_ranges_invalid_meal_period(self, mock_meal_periods_has_value, mock_auth_get_location): '''Test list_menu_ranges response when the meal period is invalid. ''' # Arrange with self.app.app_context(): mock_auth_get_location.return_value = 1 mock_meal_periods_has_value.return_value = False mock_meal_period = 'lunch' mock_period_start = '2019-01-01' mock_period_end = '2019-02-28' menu_controller = MenuController(self.request_context) # Act result = menu_controller.list_menus_range(mock_meal_period, mock_period_start, mock_period_end) # Arrange assert result.status_code == 400 assert result.get_json()['msg'] == 'Provide valid meal period ' \ 'and date range'