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_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)
Exemple #3
0
def close_account(case_id):
    try:
        closure_data = request.get_json(force=True)
        app.logger.info("Starting to close account {}".format(case_id))
        result = service.close_account(case_id, closure_data)
        closure_text = 'Account closure requested by: {}, for reason: {}'.format(
            closure_data['requester'], closure_data['close_detail'])
        service.insert_note(case_id, {
            'staff_id': closure_data['staff_id'],
            'note_text': closure_text
        })

        user_details = service.get_pending_by_id(case_id)
        user_details = {
            key: '' if value is None else value
            for (key, value) in user_details.items()
        }
        closure_details = service.get_closure_by_id(case_id)
        user_details.update(closure_details)

        insert_metric_event('account closed', user_details)

        return jsonify(result), 200
    except ApplicationError as error:
        error_msg = 'Failed to close account {} - {}'.format(
            case_id, error.message)
        app.logger.error(error_msg)

        return jsonify(error=error_msg), error.http_code
Exemple #4
0
def get_case_by_id(case_id):
    try:
        app.logger.info("Getting details for id: {}".format(case_id))
        result = service.get_pending_by_id(case_id)
        return jsonify(result)
    except ApplicationError as error:
        error_message = "Failed to get case '{}' - {}".format(
            case_id, error.message)
        app.logger.error(error_message)
        return jsonify(error=error_message), error.http_code
Exemple #5
0
def update_dataset_access(case_id):
    try:
        app.logger.info("Updating dataset access for case: {}".format(case_id))
        data = request.get_json(force=True)
        result = service.update_dataset_access(case_id, data)
        handle_dataset_access_metrics(service.get_pending_by_id(case_id),
                                      result)

        return jsonify(result), 200
    except ApplicationError as error:
        error_msg = 'Failed to update groups - {}'.format(error.message)

        return jsonify(error=error_msg), error.http_code
    def test_get_pending_by_id(self, mock_extract, mock_note, mock_case, *_):
        mocked_case = MagicMock()
        mocked_case.as_dict.return_value = {'foo': 'bar'}
        mock_case.get_case_by_id.return_value = mocked_case
        mock_note.return_value = [{'my_note': 'A note'}]
        mock_extract.return_value = [{'my_note': 'A note'}]

        result = service.get_pending_by_id('1')
        self.assertEqual(result, {
            'foo': 'bar',
            'notes': [{
                'my_note': 'A note'
            }]
        })
Exemple #7
0
def decline_case(case_id):
    try:
        decline = request.get_json(force=True)
        app.logger.info("Declining case {}, by: {}".format(
            case_id, decline['staff_id']))
        result = service.dps_action('Decline', case_id, decline)
        if not result['status_updated']:
            app.logger.error('Failed to approve case {}'.format(case_id))
            return jsonify(result), 500

        user_details = service.get_pending_by_id(case_id)
        user_details['decline_reason'] = decline['reason']

        return jsonify(result), 200

    except ApplicationError as error:
        error_msg = 'Failed to decline case - {}'.format(error.message)
        app.logger.error(error_msg)

        return jsonify(error=error_msg), error.http_code
Exemple #8
0
def approve_case(case_id):
    try:
        approval = request.get_json(force=True)
        app.logger.info('Approving case {}, by: {}'.format(
            case_id, approval['staff_id']))
        result = service.dps_action('Approve', case_id, approval)
        if not result['status_updated']:
            app.logger.error('Failed to approve case {}'.format(case_id))
            return jsonify(result), 500

        user_details = service.get_pending_by_id(case_id)

        insert_metric_event('dst action approved', user_details)

        return jsonify(result), 200

    except ApplicationError as error:
        error_msg = 'Failed to approve case - {}'.format(error.message)
        app.logger.error(error_msg)

        return jsonify(error=error_msg), error.http_code