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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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'))
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
 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)