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_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_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'}