def no_envs():
    """Context manager that disables qiskit environment variables."""
    # Remove the original variables from `os.environ`.
    # Store the original `os.environ`.
    os_environ_original = os.environ.copy()
    modified_environ = {key: value for key, value in os.environ.items()
                        if key not in VARIABLES_MAP.keys()}
    os.environ = modified_environ
    yield
    # Restore the original `os.environ`.
    os.environ = os_environ_original
Example #2
0
from qiskit.providers.ibmq.ibmqsingleprovider import IBMQSingleProvider
from qiskit.providers.ibmq.api_v2.exceptions import RequestsApiError
from qiskit.test import QiskitTestCase

from ..contextmanagers import custom_envs, no_envs

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

PROXIES = {
    'urls': {
        'http': 'http://*****:*****@127.0.0.1:5678',
        'https': 'https://*****:*****@127.0.0.1:5678'
    }
}

CREDENTIAL_ENV_VARS = VARIABLES_MAP.keys()


# TODO: NamedTemporaryFiles do not support name in Windows
@skipIf(os.name == 'nt', 'Test not supported in Windows')
class TestIBMQAccounts(QiskitTestCase):
    """Tests for the IBMQ account handling."""
    def test_enable_account(self):
        """Test enabling one account."""
        with custom_qiskitrc(), mock_ibmq_provider():
            IBMQ.enable_account('QISKITRC_TOKEN',
                                url='someurl',
                                proxies=PROXIES)

            # Compare the session accounts with the ones stored in file.
            loaded_accounts = read_credentials_from_qiskitrc()