def test_delete_vendor_when_vendor_doesnot_exist(self,
                                                     mock_vendor_repo_get):
        '''Test delete_vendor when vendor doesnot exist.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value = None
            vendor_controller = VendorController(self.request_context)

            # Act
            result = vendor_controller.delete_vendor(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Invalid or incorrect ' \
                'vendor_id provided'
    def test_delete_vendor_when_vendor_is_already_deleted(
            self, mock_vendor_repo_get):
        '''Test delete_vendor when vendor is already deleted.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value = self.mock_deleted_vendor
            vendor_controller = VendorController(self.request_context)

            # Act
            result = vendor_controller.delete_vendor(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Vendor has already ' \
                'been deleted'
    def test_delete_vendor_when_vendor_has_dependants(self,
                                                      mock_vendor_repo_get):
        '''Test delete_vendor when vendor has dependants.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value = \
                self.mock_vendor_with_dependants
            vendor_controller = VendorController(self.request_context)

            # Act
            result = vendor_controller.delete_vendor(1)

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'Vendor cannot be deleted ' \
                'because it has a child object'
    def test_delete_vendor_ok_response(self, mock_filter_by,
                                       mock_vendor_repo_update,
                                       mock_vendor_repo_get):
        '''Test delete_vendor OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_repo_get.return_value = self.mock_vendor
            mock_vendor_repo_update.return_value = self.mock_vendor
            mock_filter_by.return_value.items = [
                self.mock_vendor_engagement,
            ]
            vendor_controller = VendorController(self.request_context)

            # Act
            result = vendor_controller.delete_vendor(1)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'Vendor deleted'
Exemple #5
0
def vendor_by_id(vendor_id=None):
    if request.method == 'GET':
        message = 'vendor not found'
        vendor = VendorController.find_by_id(vendor_id)
        return {
            'vendor': vendor,
            'success': True if vendor else False,
            'message': None if vendor else message
        }
    if request.method == 'PUT':
        req_body = request.json
        res = VendorController.update_vendor(vendor_id, req_body)
        return {
            'vendor': res.get('value'),
            'success': res.get('success', False),
            'message': res.get('message')
        }
    if request.method == 'DELETE':
        res = VendorController.delete_vendor(vendor_id)
        return {
            'success': res.get('success', False),
            'message': res.get('message')
        }