def test_update_with_timeout(self, mock_patch):
     mock_patch.side_effect = Timeout(self.error_msg)
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             with self.assertRaises(ApplicationError) as context:
                 UlapdAPI.update(self, self.updated_data)
                 self.assertTrue(ApplicationError in str(context.exception))
             self.assertEqual(
                 context.exception.message,
                 'Connection to ulapd_api timed out: {}'.format(
                     self.error_msg))
             self.assertEqual(context.exception.code, 'E519')
             self.assertEqual(context.exception.http_code, 500)
    def test_update_connection_error(self, mock_patch):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_patch.side_effect = ConnectionError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    UlapdAPI.update(self, self.updated_data)

                self.assertEqual(
                    context.exception.message,
                    'Encountered an error connecting to ulapd_api: {}'.format(
                        self.error_msg))
                self.assertEqual(context.exception.code, 'E518')
                self.assertEqual(context.exception.http_code, 500)
    def test_update_http_error(self, mock_patch):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_patch.side_effect = HTTPError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    UlapdAPI.update(self, self.updated_data)

                self.assertEqual(
                    context.exception.message,
                    'Received the following response from ulapd_api: {}'.
                    format(self.error_msg))
                self.assertEqual(context.exception.code, 'E517')
                self.assertEqual(context.exception.http_code, 500)
 def test_update(self, mock_patch):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_patch.return_value.text = 'Success'
             mock_patch.return_value.status_code = 200
             response = UlapdAPI.update(self, self.updated_data)
             assert response == {'message': 'user updated'}
Пример #5
0
@handle_errors(is_get=False)
def update_user_details(case_id, data):
    case = Case.get_case_by_id(case_id)
    if case is None:
        raise ApplicationError(*errors.get('verification_api',
                                           'CASE_NOT_FOUND',
                                           filler=case_id),
                               http_code=404)

    # update preference in ulapd
    ulapd = UlapdAPI()
    ulapd_data = {'user_id': case.user_id}
    for key, value in data['updated_data'].items():
        ulapd_data[key] = value
    ulapd.update(ulapd_data)

    case.registration_data = _update_registration_data(
        dict(case.registration_data), data['updated_data'])

    if 'contactable' in data['updated_data']:
        _add_update_note(case_id, data)

    db.session.commit()

    return {'updated': True}


@handle_errors(is_get=True)
def get_dataset_list_details():
    ulapd = UlapdAPI()