Esempio n. 1
0
    def test_list_vendor_engagements_ok_response(
            self, mock_vendor_engagement_repo_filter_by,
            mock_auth_get_location, mock_pagination_meta):
        '''Test list_vendor_engagements OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_auth_get_location.return_value = 1
            mock_vendor_engagement_repo_filter_by.return_value.items = [
                self.mock_vendor_engagement,
            ]
            mock_pagination_meta.return_value = {
                'total_rows': 1,
                'total_pages': 1,
                'current_page': 1,
                'next_page': 1,
                'prev_page': 1
            }
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.list_vendor_engagements()

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
Esempio n. 2
0
    def test_delete_engagement_ok_response(self, mock_get):
        '''Test delete_engagement OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_get.return_value = self.mock_vendor_engagement_no_child
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.delete_engagement(1)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'Engagement deleted'
Esempio n. 3
0
    def test_delete_engagement_when_engagement_already_deleted(self, mock_get):
        '''Test delete_engagement when engagement is already deleted.
        '''
        # Arrange
        with self.app.app_context():
            mock_get.return_value.is_deleted = True
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.delete_engagement(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'This engagement has already' \
                ' been deleted'
Esempio n. 4
0
    def test_delete_engagement_when_engagement_has_child(self, mock_get):
        '''Test delete_engagement when engagement has a child.
        '''
        # Arrange
        with self.app.app_context():
            mock_get.return_value = self.mock_vendor_engagement
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.delete_engagement(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'This engagement cannot be' \
                ' deleted because it has a child object'
Esempio n. 5
0
    def test_get_vendor_engagement_when_request_is_bad(
            self, mock_vendor_engagement_repo_get):
        '''Test get_vendor_engagement when the request is bad.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_engagement_repo_get.return_value = None
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.get_vendor_engagement(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Bad Request'
Esempio n. 6
0
    def test_delete_engagement_when_engagement_is_invalid(self, mock_get):
        '''Test delete_engagement when engagement is already deleted.
        '''
        # Arrange
        with self.app.app_context():
            mock_get.return_value = None
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.delete_engagement(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Invalid or incorrect' \
                ' engagement_id provided'
Esempio n. 7
0
    def test_upcoming_vendor_engagements_ok_response(
            self, mock_pagination_meta, mock_get_engagement_by_date,
            mock_get_location):
        '''Test update_vendor_engagements when the request is bad.
        '''
        # Arrange
        with self.app.app_context():
            mock_pagination_meta.return_value = {
                'total_rows': 1,
                'total_pages': 1,
                'current_page': 1,
                'next_page': 1,
                'prev_page': 1
            }
            mock_get_engagement_by_date.return_value.items = [
                self.mock_vendor_engagement,
            ]
            mock_get_location.return_value = 1
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller \
                .upcoming_vendor_engagements()

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
Esempio n. 8
0
    def test_update_vendor_engagement_ok_response(self, mock_update, mock_get,
                                                  mock_request_params):
        '''Test update_vendor_engagement when engagement is invalid.
        '''
        # Arrange
        with self.app.app_context():
            mock_request_params.return_value = (1, '2019-02-11', '2019-02-11',
                                                'mock status', 'mock_reason')
            mock_get.return_value = self.mock_vendor_engagement
            mock_update.return_value = self.mock_vendor_engagement
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.update_vendor_engagement(1)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
Esempio n. 9
0
    def test_update_vendor_engagement_when_engagement_is_invalid(
            self, mock_get, mock_request_params):
        '''Test update_vendor_engagement when engagement is invalid.
        '''
        # Arrange
        with self.app.app_context():
            mock_request_params.return_value = (1, '2019-02-11', '2019-02-11',
                                                'mock status', 'mock_reason')
            mock_get.return_value = None
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.update_vendor_engagement(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Invalid or incorrect ' \
                'engagement_id provided'
Esempio n. 10
0
    def test_create_vendor_engagement_when_vendor_is_invalid(
            self, mock_get_existing_engagement, mock_get, mock_request_params):
        '''Test create_vendor_engagement when the vendor is invalid.
        '''
        # Arrange
        with self.app.app_context():
            mock_get_existing_engagement.return_value = 0
            mock_request_params.return_value = (1, '2019-02-11', '2019-02-11',
                                                'Mock status')
            mock_get.return_value = None
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.create_vendor_engagement()

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Invalid vendor_id provided'
Esempio n. 11
0
    def test_create_vendor_engagement_when_engagement_already_exists(
            self, mock_get_existing_engagement, mock_get, mock_request_params):
        '''Test create_vendor_engagement when engagement already exists.
        '''
        # Arrange
        with self.app.app_context():
            mock_request_params.return_value = (1, '2019-02-11', '2019-02-11',
                                                'mock status')
            mock_get.return_value = self.mock_vendor
            mock_get_existing_engagement.return_value = 1
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.create_vendor_engagement()

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'An engagement already exists' \
                ' for this period. Kindly disable engagement first.'
Esempio n. 12
0
    def test_create_vendor_engagement_ok_response(self,
                                                  mock_new_vendor_engagement,
                                                  mock_get_existing_engagement,
                                                  mock_get,
                                                  mock_request_params):
        '''Test create_vendor_engagement OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_request_params.return_value = (1, '2019-02-11', '2019-02-11',
                                                'mock status')
            mock_get.return_value = self.mock_vendor
            mock_get_existing_engagement.return_value = 0
            mock_new_vendor_engagement.return_value = \
                self.mock_vendor_engagement
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller.create_vendor_engagement()

            # Assert
            assert result.status_code == 201
            assert result.get_json()['msg'] == 'OK'
Esempio n. 13
0
    def test_list_vendor_engagements_by_vendor_when_vendor_is_disabled(
            self, mock_vendor_repo_get):
        '''Test list_vendor_engagements when vendor is disabled.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value.is_active = False
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller. \
                list_vendor_engagements_by_vendor(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Vendor is disabled'
Esempio n. 14
0
    def test_list_vendor_engagements_by_vendor_when_vendor_is_invalid(
            self, mock_vendor_repo_get):
        '''Test list_vendor_engagement_by_vendor when the vendor is invalid
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value.is_deleted = True
            vendor_engagement_controller = VendorEngagementController(
                self.request_context)

            # Act
            result = vendor_engagement_controller \
                .list_vendor_engagements_by_vendor(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Invalid Vendor'
Esempio n. 15
0
from app.blueprints.base_blueprint import Blueprint, BaseBlueprint, request, Security, Auth
from app.controllers.vendor_engagement_controller import VendorEngagementController
from flasgger import swag_from

engagement_blueprint = Blueprint('engagements',
                                 __name__,
                                 url_prefix='{}/engagements'.format(
                                     BaseBlueprint.base_url_prefix))

vendor_engagement_controller = VendorEngagementController(request)


@engagement_blueprint.route('/', methods=['GET'])
@swag_from('documentation/get_all_vendor_engagements.yml')
def list_engagements():
    return vendor_engagement_controller.list_vendor_engagements()


@engagement_blueprint.route('/vendor/<int:vendor_id>', methods=['GET'])
@swag_from('documentation/get_all_vendor_engagements_by_vendor_id.yml')
def list_engagements_by_vendor(vendor_id):
    return vendor_engagement_controller.list_vendor_engagements_by_vendor(
        vendor_id)


@engagement_blueprint.route('/upcoming', methods=['GET'])
@swag_from('documentation/get_all_upcoming_vendor_engagement.yml')
def upcoming_engagements():
    return vendor_engagement_controller.upcoming_vendor_engagements()