def test_user_hubs(self): """Check the user hubs of the QX API.""" client = AuthClient(self.dependencies.provider._client_params) user_hubs = client.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): """Should raise RequestApiError with ProxyError using AuthClient.""" with self.assertRaises(RequestsApiError) as context_manager: _ = AuthClient( ClientParameters( token=self.dependencies.token, url=self.dependencies.url, proxies=ProxyConfiguration(urls=INVALID_ADDRESS_PROXIES), ) ) self.assertIsInstance(context_manager.exception.__cause__, ProxyError)
def test_proxies_authclient(self): """Should reach the proxy using AuthClient.""" pproxy_desired_access_log_line_ = pproxy_desired_access_log_line( self.dependencies.url ) _ = AuthClient( ClientParameters( token=self.dependencies.token, url=self.dependencies.url, proxies=ProxyConfiguration(urls=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): """Check the user urls of the QX API.""" client = AuthClient(self.dependencies.provider._client_params) 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): """Check the version of the QX API.""" client = AuthClient(self.dependencies.provider._client_params) version = client.api_version() self.assertIsNotNone(version)
def test_url_unreachable(self): """Test login against an invalid (malformed) URL.""" with self.assertRaises(ApiError): _ = AuthClient( ClientParameters(token=self.dependencies.token, url="INVALID_URL"))
def test_invalid_token(self): """Test login using invalid token.""" with self.assertRaises(ApiError): _ = AuthClient( ClientParameters(token="INVALID_TOKEN", url=self.dependencies.url))
def test_url_404(self): """Test login against a 404 URL""" url_404 = re.sub(r"/api.*$", "/api/TEST_404", self.dependencies.url) with self.assertRaises(ApiError): _ = AuthClient( ClientParameters(token=self.dependencies.token, url=url_404))
def test_valid_login(self): """Test valid authentication.""" client = AuthClient(self.dependencies.provider._client_params) self.assertTrue(client.access_token) self.assertTrue(client.api_token)