def test_add_api_superuser_to_project_logs_error(self): auth.api_client_set().AndRaise(RuntimeError('catch me')) self.app.logger.exception(IsA(basestring), 'PID', IsA(RuntimeError)) self.mox.ReplayAll() with self.app.test_request_context(): auth.add_api_superuser_to_project('PID')
def check_connection(app): """Attempt to connect to identity service""" try: with app.test_request_context(): auth.api_client_set() return True except Exception, e: app.logger.error('Configuration check failed (%s)', e)
def test_client_set_for_tenant_fallback(self): tcs = self._fake_client_set_factory() self.mock_client_set().AndReturn(tcs) tcs.http_client.authenticate()\ .AndRaise(Unauthorized('denied')) auth.api_client_set('PID').AndReturn('REPLY') self.mox.ReplayAll() with self.app.test_request_context(): self.install_fake_auth() result = auth.client_set_for_tenant('PID', fallback_to_api=True) self.assertEquals('REPLY', result)
def test_add_api_superuser_to_project_works(self): tcs = self._fake_client_set_factory() tcs.http_client.access['user'] = { 'id': 'API_SU_UID', 'roles': [ { 'id': 'AR_ID', 'name': 'admin' } ] } auth.api_client_set().AndReturn(tcs) tcs.identity_admin.roles.add_user_role('API_SU_UID', 'AR_ID', 'PID') self.mox.ReplayAll() with self.app.test_request_context(): auth.add_api_superuser_to_project('PID')
def test_add_api_superuser_to_project_works(self): tcs = self._fake_client_set_factory() tcs.http_client.access['user'] = { 'id': 'API_SU_UID', 'roles': [{ 'id': 'AR_ID', 'name': 'admin' }] } auth.api_client_set().AndReturn(tcs) tcs.identity_admin.roles.add_user_role('API_SU_UID', 'AR_ID', 'PID') self.mox.ReplayAll() with self.app.test_request_context(): auth.add_api_superuser_to_project('PID')
def test_api_cs_for_project(self): auth._client_set('test_admin', 'test_p@ssw0rd', tenant_id='PID') \ .AndReturn('FAKE_CS') auth.admin_role_id('FAKE_CS').AndReturn('ROLE') self.mox.ReplayAll() with self.app.test_request_context(): cs = auth.api_client_set('PID') self.assertEquals(cs, 'FAKE_CS')
def test_api_cs_for_project_denied_at_first(self): auth._client_set('test_admin', 'test_p@ssw0rd', tenant_id='PID') \ .AndRaise(Unauthorized('denied')) auth.add_api_superuser_to_project('PID') auth._client_set('test_admin', 'test_p@ssw0rd', tenant_id='PID') \ .AndReturn('FAKE_CS') auth.admin_role_id('FAKE_CS').AndReturn('ROLE') self.mox.ReplayAll() with self.app.test_request_context(): cs = auth.api_client_set('PID') self.assertEquals(cs, 'FAKE_CS')