コード例 #1
0
    def test_update_menu_ok_response(self, mock_meal_item_repo_get,
                                     mock_menu_repo_update, mock_menu_repo_get,
                                     mock_menu_controller_request_params):
        '''Test update_menu when the response is OK.
        '''
        # Arrange
        with self.app.app_context():
            mock_menu_controller_request_params.return_value = ('2019-01-01',
                                                                'lunch', 1, 1,
                                                                1, '1,1',
                                                                '1,2', 1)
            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.return_value = mock_menu
            mock_menu_repo_update.return_value = mock_menu
            mock_meal_item_repo_get.return_value = mock_meal_item
            mock_menu_id = 1
            menu_controller = MenuController(self.request_context)

            # Act
            result = menu_controller.update_menu(mock_menu_id)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
コード例 #2
0
    def test_update_menu_when_menu_doesnot_exist(
            self, mock_menu_repo_get, mock_menu_controller_request_params):
        '''Test update_menu when the menu does not exist.
        '''
        # Arrange
        with self.app.app_context():
            mock_menu_controller_request_params.return_value = (None, None,
                                                                None, None,
                                                                None, None,
                                                                None, None)
            mock_menu_repo_get.return_value = None
            mock_menu_id = 1
            menu_controller = MenuController(self.request_context)

            # Act
            result = menu_controller.update_menu(mock_menu_id)

            # Assert
            assert result.status_code == 404
            assert result.get_json()['msg'] == 'This menu_id ' \
                'does not exist'
コード例 #3
0
    def test_update_menu_when_menu_is_deleted(
            self, mock_menu_repo_get, mock_menu_controller_request_params):
        '''Test update_menu when the menu is deleted.
        '''
        # Arrange
        with self.app.app_context():
            mock_deleted_menu = Menu(is_deleted=True)
            mock_menu_repo_get.return_value = mock_deleted_menu
            mock_menu_controller_request_params.return_value = (None, None,
                                                                None, None,
                                                                None, None,
                                                                None, None)
            mock_menu_id = 1
            menu_controller = MenuController(mock_menu_id)

            # Act
            result = menu_controller.update_menu(mock_menu_id)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'This menu is ' \
                'already deleted'