def test_acknowledge(self, mock_post):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_post.return_value.text = 'Success'
             mock_post.return_value.status_code = 200
             response = AccountAPI.acknowledge(self, '1234-567-890')
             assert response == {'message': 'acknowledged'}
 def test_get(self, mock_get):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_get.return_value.json.return_value = 'Success'
             mock_get.return_value.status_code = 200
             response = AccountAPI.get(self, '1234-567-890')
             self.assertEqual(response, 'Success')
 def test_update_groups(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 = AccountAPI.update_groups(self, {'nps_sample': True},
                                                 '11-22')
             assert response == {'message': 'groups updated'}
 def test_create(self, mock_create, mock_post):
     data = {'user_id': '1234'}
     mock_create.return_value = {'user_id': '1234'}
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_post.return_value.json.return_value = 'Success'
             mock_post.return_value.status_code = 200
             response = VerificationAPI.create(self, data)
             self.assertEqual(response, 'Success')
 def test_create(self, mock_create, mock_post):
     data = {'email': '*****@*****.**'}
     mock_create.return_value = {'email': '*****@*****.**'}
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_post.return_value.json.return_value = 'Success'
             mock_post.return_value.status_code = 200
             response = AccountAPI.create(self, data)
             self.assertEqual(response, 'Success')
 def test_handle_role(self, mock_post):
     with app.app_context() as ac:
         ac.g.trace_id = None
         ac.g.requests = requests.Session()
         with app.test_request_context():
             mock_post.return_value.text = 'Success'
             mock_post.return_value.status_code = 200
             response = AccountAPI.handle_role(self, {
                 'groups': {
                     'nps_sample': True
                 },
                 'ldap_id': '11-22'
             })
             assert response == {'message': 'success'}
 def test_get_with_timeout(self, mock_get):
     mock_get.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:
                 AccountAPI.get(self, '1234-567-890')
                 self.assertTrue(ApplicationError in str(context.exception))
             self.assertEqual(
                 context.exception.message,
                 'Connection to account_api timed out: {}'.format(
                     self.error_msg))
             self.assertEqual(context.exception.code, 'E711')
             self.assertEqual(context.exception.http_code, 500)
    def test_get_connection_error(self, mock_get):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_get.side_effect = ConnectionError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    AccountAPI.get(self, '1234-567-890')

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

                with self.assertRaises(ApplicationError) as context:
                    AccountAPI.get(self, '1234-567-890')

                self.assertEqual(
                    context.exception.message,
                    'Received the following response from account_api: {}'.
                    format(self.error_msg))
                self.assertEqual(context.exception.code, 'E709')
                self.assertEqual(context.exception.http_code, 500)
 def test_update_groups_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:
                 AccountAPI.update_groups(self, {'nps_sample': True},
                                          '11-22')
                 self.assertTrue(ApplicationError in str(context.exception))
             self.assertEqual(
                 context.exception.message,
                 'Connection to account_api timed out: {}'.format(
                     self.error_msg))
             self.assertEqual(context.exception.code, 'E711')
             self.assertEqual(context.exception.http_code, 500)
 def test_create_with_timeout(self, mock_create, mock_post):
     mock_post.side_effect = Timeout(self.error_msg)
     data = {'foo': 'bar'}
     mock_create.return_value = {'foo': 'bar'}
     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:
                 VerificationAPI.create(self, data)
                 self.assertTrue(ApplicationError in str(context.exception))
             self.assertEqual(
                 context.exception.message,
                 'Connection to verification_api timed out: {}'.format(
                     self.error_msg))
             self.assertEqual(context.exception.code, 'E714')
             self.assertEqual(context.exception.http_code, 500)
    def test_update_groups_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:
                    AccountAPI.update_groups(self, {'nps_sample': True},
                                             '11-22')

                self.assertEqual(
                    context.exception.message,
                    'Received the following response from account_api: {}'.
                    format(self.error_msg))
                self.assertEqual(context.exception.code, 'E709')
                self.assertEqual(context.exception.http_code, 500)
    def test_create_connection_error(self, mock_create, mock_post):
        data = {'foo': 'bar'}
        mock_create.return_value = {'foo': 'bar'}
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_post.side_effect = ConnectionError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    VerificationAPI.create(self, data)

                self.assertEqual(
                    context.exception.message,
                    'Encountered an error connecting to verification_api: {}'.
                    format(self.error_msg))
                self.assertEqual(context.exception.code, 'E713')
                self.assertEqual(context.exception.http_code, 500)
    def test_create_http_error(self, mock_create, mock_post):
        data = {'foo': 'bar'}
        mock_create.return_value = {'foo': 'bar'}
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_post.side_effect = HTTPError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    VerificationAPI.create(self, data)

                self.assertEqual(
                    context.exception.message,
                    'Received the following response from verification_api: {}'
                    .format(self.error_msg))
                self.assertEqual(context.exception.code, 'E712')
                self.assertEqual(context.exception.http_code, 500)
    def test_handle_role_connection_error(self, mock_post):
        with app.app_context() as ac:
            ac.g.trace_id = None
            ac.g.requests = requests.Session()
            with app.test_request_context():
                mock_post.side_effect = ConnectionError(self.error_msg)

                with self.assertRaises(ApplicationError) as context:
                    AccountAPI.handle_role(self, {
                        'groups': {
                            'nps_sample': True
                        },
                        'ldap_id': '11-22'
                    })

                self.assertEqual(
                    context.exception.message,
                    'Encountered an error connecting to account_api: {}'.
                    format(self.error_msg))
                self.assertEqual(context.exception.code, 'E710')
                self.assertEqual(context.exception.http_code, 500)