Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy pass through test #1014

Merged
merged 3 commits into from
Oct 3, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions test/python/ibmq/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
from qiskit.backends.ibmq.credentials._environ import VARIABLES_MAP
from qiskit.backends.ibmq.ibmqprovider import QE_URL
from qiskit.backends.ibmq.ibmqsingleprovider import IBMQSingleProvider
from ..common import QiskitTestCase
from ..common import QiskitTestCase, requires_qe_access


IBMQ_TEMPLATE = 'https://localhost/api/Hubs/{}/Groups/{}/Projects/{}'

PROXIES = {'urls': {
'http': 'http://user:[email protected]:5678',
'https': 'https://user:[email protected]:5678'}
}


# TODO: NamedTemporaryFiles do not support name in Windows
@skipIf(os.name == 'nt', 'Test not supported in Windows')
Expand All @@ -37,7 +42,7 @@ def test_enable_account(self):
"""Test enabling one account."""
with custom_qiskitrc(), mock_ibmq_provider():
qiskit.IBMQ.enable_account('QISKITRC_TOKEN', url='someurl',
proxies={'http': 'foo'})
proxies=PROXIES)

# Compare the session accounts with the ones stored in file.
loaded_accounts = read_credentials_from_qiskitrc()
Expand All @@ -46,7 +51,7 @@ def test_enable_account(self):
self.assertEqual(loaded_accounts, {})
self.assertEqual('QISKITRC_TOKEN', provider.credentials.token)
self.assertEqual('someurl', provider.credentials.url)
self.assertEqual({'http': 'foo'}, provider.credentials.proxies)
self.assertEqual(PROXIES, provider.credentials.proxies)

def test_enable_multiple_accounts(self):
"""Test enabling multiple accounts, combining QX and IBMQ."""
Expand All @@ -73,7 +78,7 @@ def test_save_account(self):
"""Test saving one account."""
with custom_qiskitrc(), mock_ibmq_provider():
qiskit.IBMQ.save_account('QISKITRC_TOKEN', url=QE_URL,
proxies={'http': 'foo'})
proxies=PROXIES)

# Compare the session accounts with the ones stored in file.
stored_accounts = read_credentials_from_qiskitrc()
Expand Down Expand Up @@ -143,6 +148,17 @@ def test_delete_all_accounts(self):
self.assertEqual(len(qiskit.IBMQ._accounts), 0)
self.assertEqual(len(read_credentials_from_qiskitrc()), 0)

@requires_qe_access
def test_pass_bad_proxy(self, qe_token, qe_url):
"""Test proxy pass through."""
failed = False
try:
qiskit.IBMQ.enable_account(qe_token, qe_url, proxies=PROXIES)
except ConnectionError as excep:
if 'ProxyError' in str(excep):
failed = True
self.assertTrue(failed)


# TODO: NamedTemporaryFiles do not support name in Windows
@skipIf(os.name == 'nt', 'Test not supported in Windows')
Expand Down