def test_user_hubs(self, qe_token, qe_url): """Check the user hubs of the QX API.""" api = AuthClient(qe_token, qe_url) user_hubs = api.user_hubs() self.assertIsNotNone(user_hubs) for user_hub in user_hubs: with self.subTest(user_hub=user_hub): self.assertTrue('hub' in user_hub and 'group' in user_hub and 'project' in user_hub)
def test_invalid_proxy_address_authclient(self, qe_token, qe_url): """Should raise RequestApiError with ProxyError using AuthClient.""" with self.assertRaises(RequestsApiError) as context_manager: _ = AuthClient(qe_token, qe_url, proxies=INVALID_ADDRESS_PROXIES) self.assertIsInstance(context_manager.exception.original_exception, ProxyError)
def test_proxies_authclient(self, qe_token, qe_url): """Should reach the proxy using AuthClient.""" pproxy_desired_access_log_line_ = pproxy_desired_access_log_line(qe_url) _ = AuthClient(qe_token, qe_url, proxies=VALID_PROXIES) self.proxy_process.terminate() # kill to be able of reading the output self.assertIn(pproxy_desired_access_log_line_, self.proxy_process.stdout.read().decode('utf-8'))
def test_user_urls(self, qe_token, qe_url): """Check the user urls of the QX API.""" client = AuthClient(qe_token, qe_url) user_urls = client.user_urls() self.assertIsNotNone(user_urls) self.assertTrue('http' in user_urls and 'ws' in user_urls)
def test_api_version(self, qe_token, qe_url): """Check the version of the QX API.""" client = AuthClient(qe_token, qe_url) version = client.api_version() self.assertIsNotNone(version)
def test_url_unreachable(self, qe_token, qe_url): """Test login against an invalid (malformed) URL.""" qe_url = 'INVALID_URL' with self.assertRaises(ApiError): _ = AuthClient(qe_token, qe_url)
def test_invalid_token(self, qe_token, qe_url): """Test login using invalid token.""" qe_token = 'INVALID_TOKEN' with self.assertRaises(ApiError): _ = AuthClient(qe_token, qe_url)
def test_url_404(self, qe_token, qe_url): """Test login against a 404 URL""" url_404 = re.sub(r'/api.*$', '/api/TEST_404', qe_url) with self.assertRaises(ApiError): _ = AuthClient(qe_token, url_404)
def test_valid_login(self, qe_token, qe_url): """Test valid authentication.""" client = AuthClient(qe_token, qe_url) self.assertTrue(client.base_api.session._access_token)
def test_invalid_proxy_port_authclient(self, qe_token, qe_url): """Should raise RequestApiError with ProxyError using AuthClient.""" with self.assertRaises(RequestsApiError) as context_manager: _ = AuthClient(qe_token, qe_url, proxies=INVALID_PORT_PROXIES) self.assertIsInstance(context_manager.exception.__cause__, ProxyError)
def test_valid_login(self, qe_token, qe_url): """Test valid authenticating against IBM Q.""" client = AuthClient(qe_token, qe_url) self.assertTrue(client.client_api.session.access_token)