def test_insert_note_sql_error(self, mock_case, *_):
        mock_case.get_case_by_id.side_effect = self.error
        with self.assertRaises(ApplicationError) as context:
            service.insert_note('1', {})

        expected_err = ('verification_api', 'SQLALCHEMY_ERROR')
        self.assertEqual(context.exception.message,
                         errors.get_message(*expected_err, filler=self.error))
        self.assertEqual(context.exception.code,
                         errors.get_code(*expected_err))
Beispiel #2
0
    def test_get_api_datasets_not_found(self, mock_auth, mock_ulapd_api):
        error = ('ulapd_ui', 'NO_DATASETS_FOUND')
        instance = mock_ulapd_api.return_value
        instance.get_datasets.return_value = []

        with self.assertRaises(ApplicationError) as cm:
            get_api_datasets()

        self.assertEqual(cm.exception.message, errors.get_message(*error))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
    def test_insert_case_error(self, mock_case, *_):
        error = ('verification_api', 'VERIFICATION_ERROR')
        mock_case.side_effect = ApplicationError(
            *errors.get(*error, filler='TEST ERR'))
        with self.assertRaises(ApplicationError) as context:
            service.insert_case({'foo': 'bar'})

        self.assertEqual(context.exception.message,
                         errors.get_message(*error, filler='TEST ERR'))
        self.assertEqual(context.exception.code, errors.get_code(*error))
Beispiel #4
0
    def test_get_all_metrics_error(self, mock_service):
        mock_service.retrieve_all_metrics.side_effect = ApplicationError(
            *errors.get(*self.sql_error))
        expected_err_msg = errors.get_message(*self.sql_error)

        response = self.app.get('/v1/metric', headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual("Failed to retrieve metrics - " + expected_err_msg,
                         response_body['error'])
    def test_get_pending_by_id_no_row(self, mock_case, *_):
        mock_case.get_case_by_id.return_value = None
        with self.assertRaises(ApplicationError) as context:
            service.get_pending_by_id('1')

        expected_err = ('verification_api', 'CASE_NOT_FOUND')
        expected_err_message = errors.get_message(*expected_err, filler='1')
        expected_err_code = errors.get_code(*expected_err)

        self.assertEqual(context.exception.message, expected_err_message)
        self.assertEqual(context.exception.code, expected_err_code)
    def test_decline_reason_error(self, mock_service, *_):
        mock_service.get_decline_reasons.side_effect = ApplicationError(
            *errors.get(*self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        response = self.app.get('/v1/decline-reasons', headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual("Failed to get decline reasons - " + expected_err_msg,
                         response_body['error'])
    def test_decline_reasons_error(self, mock_extract, *_):
        error = ('verification_api', 'VERIFICATION_ERROR')
        mock_extract.side_effect = ApplicationError(
            *errors.get(*error, filler='TEST ERR'))

        with self.assertRaises(ApplicationError) as context:
            service.get_decline_reasons()

        self.assertEqual(context.exception.message,
                         errors.get_message(*error, filler='TEST ERR'))
        self.assertEqual(context.exception.code, errors.get_code(*error))
    def test_get_dataset_list_details_error(self, mock_service, *_):
        mock_service.get_dataset_list_details.side_effect = ApplicationError(
            *errors.get(*self.test_error))

        response = self.app.get('/v1/dataset-list-details',
                                headers=self.headers)

        expected_err = 'Failed to get detailed dataset list - {}'.format(
            errors.get_message(*self.test_error))
        self.assertEqual(response.get_json()['error'], expected_err)
        self.assertEqual(response.status_code, 500)
Beispiel #9
0
    def test_get_dataset_history_no_row(self, mock_dataset, *_):
        mock_dataset.get_dataset_by_name.return_value = None
        with self.assertRaises(ApplicationError) as context:
            service.get_dataset_history('ccod')

        expected_err = ('ulapd_api', 'DATASET_NOT_FOUND')
        expected_err_message = errors.get_message(*expected_err, filler='ccod')
        expected_err_code = errors.get_code(*expected_err)

        self.assertEqual(context.exception.message, expected_err_message)
        self.assertEqual(context.exception.code, expected_err_code)
    def test_get_worklist_error(self, mock_service, *_):
        mock_service.get_pending.side_effect = ApplicationError(*errors.get(
            *self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        response = self.app.get('/v1/worklist', headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual("Failed to retrieve worklist - " + expected_err_msg,
                         response_body['error'])
    def test_get_users_dataset_activity_error(self, mock_service, *_):
        mock_service.get_dataset_activity.side_effect = ApplicationError(
            *errors.get(*self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        response = self.app.get('/v1/dataset-activity/1', headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        expected_err = 'Failed to get dataset activity - {}'.format(
            expected_err_msg)
        self.assertEqual(expected_err, response_body['error'])
    def test_manage_case_lock_case_not_found(self, mock_case, *_):
        mock_case.get_case_by_id.return_value = None
        test_case_id = '1'
        with self.assertRaises(ApplicationError) as context:
            service.manage_case_lock(test_case_id)

        expected_err = ('verification_api', 'CASE_NOT_FOUND')
        expected_err_message = errors.get_message(*expected_err, filler='1')
        expected_err_code = errors.get_code(*expected_err)

        self.assertEqual(context.exception.message, expected_err_message)
        self.assertEqual(context.exception.code, expected_err_code)
    def test_get_pending_error(self, mock_extract, mock_case, *_):
        error = ('verification_api', 'VERIFICATION_ERROR')
        mock_extract.side_effect = ApplicationError(
            *errors.get(*error, filler='TEST ERR'))

        with self.assertRaises(ApplicationError) as context:
            mock_case.get_pending.return_value = _generate_test_profile()
            service.get_pending()

        self.assertEqual(context.exception.message,
                         errors.get_message(*error, filler='TEST ERR'))
        self.assertEqual(context.exception.code, errors.get_code(*error))
    def test_dps_action_error(self, mock_account, mock_case, *_):
        error = ('verification_api', 'VERIFICATION_ERROR')
        mock_account.side_effect = ApplicationError(
            *errors.get(*error, filler='TEST ERROR'))
        mock_case.get_case_by_id.return_value = _generate_test_profile()

        with self.assertRaises(ApplicationError) as context:
            service.dps_action('Approve', '1', {'staff_id': 'LRTM101'})

        expected_err = errors.get_message(*error, filler='TEST ERROR')
        self.assertEqual(context.exception.message, expected_err)
        self.assertEqual(context.exception.code, errors.get_code(*error))
    def test_dps_action_no_row(self, mock_case, *_):
        mock_case.get_case_by_id.return_value = None

        with self.assertRaises(ApplicationError) as context:
            service.dps_action('Approve', '1', {'staff_id': 'LRTM101'})

        expected_err = ('verification_api', 'CASE_NOT_FOUND')
        expected_err_message = errors.get_message(*expected_err, filler='1')
        expected_err_code = errors.get_code(*expected_err)

        self.assertEqual(context.exception.message, expected_err_message)
        self.assertEqual(context.exception.code, expected_err_code)
    def test_retrieve_metrics_by_id_no_row(self, mock_extract, *_):
        mock_extract.return_value = []
        with self.assertRaises(ApplicationError) as context:
            service.retrieve_metrics_by_id('123-123-123')

        expected_err = ('dps_metric_api', 'CASE_NOT_FOUND')
        expected_err_message = errors.get_message(*expected_err,
                                                  filler='123-123-123')
        expected_err_code = errors.get_code(*expected_err)

        self.assertEqual(context.exception.message, expected_err_message)
        self.assertEqual(context.exception.code, expected_err_code)
Beispiel #17
0
    def test_get_api_dataset_by_name_not_found(self, mock_auth,
                                               mock_ulapd_api):
        error = ('ulapd_ui', 'DATASET_NOT_FOUND')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = None

        with self.assertRaises(ApplicationError) as cm:
            get_api_dataset_by_name('abc')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='abc'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
    def test_unlock_error(self, mock_service, *_):
        mock_service.manage_case_lock.side_effect = ApplicationError(
            *errors.get(*self.test_error))

        response = self.app.post('/v1/case/1/unlock',
                                 json={},
                                 headers=self.headers)
        response_body = response.get_json()

        expected_error_msg = errors.get_message(*self.test_error)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(response_body['error'], expected_error_msg)
Beispiel #19
0
    def test_get_metric_by_user_id_error(self, mock_service):
        mock_service.retrieve_metrics_by_id.side_effect = ApplicationError(
            *errors.get(*self.sql_error))
        expected_err_msg = errors.get_message(*self.sql_error)

        response = self.app.get('/v1/metric/123-456-789-abc',
                                headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual(
            "Failed to retrieve metrics for user: 123-456-789-abc with error: "
            + expected_err_msg, response_body['error'])
    def test_get_groups_error(self, mock_service, *_):
        case_id = 999
        mock_service.get_groups.side_effect = ApplicationError(*errors.get(
            *self.test_error))

        response = self.app.get('/v1/groups/{}'.format(case_id),
                                headers=self.headers)

        expected_err = 'Failed to get groups - {}'.format(
            errors.get_message(*self.test_error))
        mock_service.get_groups.assert_called_once_with(str(case_id))
        self.assertEqual(response.get_json()['error'], expected_err)
        self.assertEqual(response.status_code, 500)
    def test_dps_action_sql_error(self, mock_case, *_):
        with self.assertRaises(ApplicationError) as context:
            mock_case.get_case_by_id.side_effect = self.error
            service.dps_action('Approve', '1', {'staff_id': 'LRTM101'})

        self.assertEqual(
            context.exception.message,
            errors.get_message("verification_api",
                               "SQLALCHEMY_ERROR",
                               filler=self.error))
        self.assertEqual(
            errors.get_code("verification_api", "SQLALCHEMY_ERROR"),
            context.exception.code)
    def test_update_user_details_sql_error(self, mock_case, *_):
        with self.assertRaises(ApplicationError) as context:
            mock_case.get_case_by_id.side_effect = self.error
            service.update_user_details(1, {'foo': 'bar'})

        self.assertEqual(
            context.exception.message,
            errors.get_message("verification_api",
                               "SQLALCHEMY_ERROR",
                               filler=self.error))
        self.assertEqual(
            errors.get_code("verification_api", "SQLALCHEMY_ERROR"),
            context.exception.code)
    def test_notepad_error(self, mock_service, *_):
        mock_service.insert_note.side_effect = ApplicationError(*errors.get(
            *self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)
        json_body = {'note_text': 'A note', 'staff_id': 'AA123ZZ'}
        response = self.app.post('/v1/case/1/note',
                                 json=json_body,
                                 headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual("Failed to insert note - " + expected_err_msg,
                         response_body['error'])
    def test_decline_error(self, mock_service, *_):
        mock_service.dps_action.side_effect = ApplicationError(*errors.get(
            *self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        response = self.app.post('/v1/case/1/decline',
                                 json=self.decline_body,
                                 headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        self.assertEqual("Failed to decline case - " + expected_err_msg,
                         response_body['error'])
    def test_get_pending_by_id_sql_error(self, mock_case, *_):
        with self.assertRaises(ApplicationError) as context:
            mock_case.get_case_by_id.side_effect = self.error
            service.get_pending_by_id('1')

        self.assertEqual(
            context.exception.message,
            errors.get_message("verification_api",
                               "SQLALCHEMY_ERROR",
                               filler=self.error))
        self.assertEqual(
            errors.get_code("verification_api", "SQLALCHEMY_ERROR"),
            context.exception.code)
    def test_search_error(self, mock_service, *_):
        mock_service.perform_search.side_effect = ApplicationError(*errors.get(
            *self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        json_body = {"first_name": "Andreea"}
        response = self.app.post('/v1/search',
                                 json=json_body,
                                 headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        expected_err = 'Failed to perform search - {}'.format(expected_err_msg)
        self.assertEqual(expected_err, response_body['error'])
    def test_auto_close_error(self, mock_service, mock_audit, *_):
        mock_service.auto_close.side_effect = ApplicationError(*errors.get(
            *self.test_error))
        expected_err_msg = errors.get_message(*self.test_error)

        response = self.app.post('/v1/case/123456/auto_close',
                                 json=self.close_body,
                                 headers=self.headers)

        self.assertEqual(500, response.status_code)
        response_body = response.get_json()
        expected_err = 'Failed to auto close account for ldap_id: 123456 - {}'.format(
            expected_err_msg)
        self.assertEqual(expected_err, response_body['error'])
Beispiel #28
0
    def test_get_api_download_link_not_agreed(self, mock_auth, mock_ulapd_api):
        error = ('ulapd_ui', 'NO_LICENCE_SIGNED')
        instance = mock_ulapd_api.return_value
        instance.get_dataset_by_name.return_value = data.get_dataset_by_name[
            'ccod']

        mock_auth.return_value = data.user_details_no_agreements

        with self.assertRaises(ApplicationError) as cm:
            get_api_download_link('ccod', 'CCOD_FULL.CSV')

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='ccod'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))
    def test_get_worklist_item_error(self, mock_service, *_):
        mock_service.get_pending_by_id.side_effect = ApplicationError(
            *errors.get(*self.test_error))
        test_id = 1

        response = self.app.get('/v1/case/{}'.format(test_id),
                                headers=self.headers)
        response_body = response.get_json()

        expected_err_msg = errors.get_message(*self.test_error)
        expected_err_msg = "Failed to get case '{}' - {}".format(
            test_id, expected_err_msg)
        self.assertEqual(500, response.status_code)
        self.assertEqual(expected_err_msg, response_body['error'])
Beispiel #30
0
    def test_authenticate_fail(self, mock_request):
        error = ('ulapd_ui', 'API_KEY_ERROR')
        m = Mock()
        m.get_user_details.side_effect = ApplicationError('Test')

        mock_request.headers = {}
        mock_request.headers['Authorization'] = '1234'

        with self.assertRaises(ApplicationError) as cm:
            _authenticate(m)

        self.assertEqual(cm.exception.message,
                         errors.get_message(*error, filler='1234'))
        self.assertEqual(cm.exception.code, errors.get_code(*error))