示例#1
0
 def run(self):
     """ h/g/p thread process """
     try:
         self._hgp = []
         if self._thread_queue is not None:
             self._thread_queue.put(CredentialsView._START)
         # pylint: disable=no-name-in-module, import-error
         if self._token:
             from qiskit.providers.ibmq import IBMQFactory
             ibmq = IBMQFactory()
             ibmq.enable_account(self._token, proxies=self._proxies)
             providers = ibmq.providers()
             for provider in providers:
                 self._hgp.append(
                     (provider.credentials.hub, provider.credentials.group,
                      provider.credentials.project))
     except Exception as ex:  # pylint: disable=broad-except
         logger.warning('IBMQ account Account Failure. Proxies:%s :%s',
                        self._proxies, ex)
     finally:
         if self._thread_queue is not None:
             self._thread_queue.put(CredentialsView._STOP)
    def test_proxies_factory(self, qe_token, qe_url):
        """Should reach the proxy using factory.enable_account."""
        factory = IBMQFactory()
        provider = factory.enable_account(qe_token, qe_url,
                                          proxies={'urls': VALID_PROXIES})

        self.proxy_process.terminate()  # kill to be able of reading the output

        auth_line = pproxy_desired_access_log_line(qe_url)
        api_line = pproxy_desired_access_log_line(provider.credentials.url)
        proxy_output = self.proxy_process.stdout.read().decode('utf-8')

        # Check if the authentication call went through proxy.
        self.assertIn(auth_line, proxy_output)
        # Check if the API call (querying providers list) went through proxy.
        self.assertIn(api_line, proxy_output)