def test_store_credentials_overwrite(self): """Test overwriting qiskitrc credentials.""" credentials = Credentials('QISKITRC_TOKEN', url=QE2_AUTH_URL) credentials2 = Credentials('QISKITRC_TOKEN_2', url=QE2_AUTH_URL) factory = IBMQFactory() with custom_qiskitrc(): store_credentials(credentials) # Cause all warnings to always be triggered. warnings.simplefilter("always") # Get the logger for `store_credentials`. config_rc_logger = logging.getLogger(store_credentials.__module__) # Attempt overwriting. with self.assertLogs(logger=config_rc_logger, level='WARNING') as log_records: store_credentials(credentials) self.assertIn('already present', log_records.output[0]) with no_file('Qconfig.py'), no_envs( CREDENTIAL_ENV_VARS), mock_ibmq_provider(): # Attempt overwriting. store_credentials(credentials2, overwrite=True) factory.load_account() # Ensure that the credentials are the overwritten ones. self.assertEqual(factory._credentials, credentials2)
def test_store_credentials_overwrite(self): """Test overwriting qiskitrc credentials.""" credentials = Credentials('QISKITRC_TOKEN', url=QE2_AUTH_URL) credentials2 = Credentials('QISKITRC_TOKEN_2', url=QE2_AUTH_URL) factory = IBMQFactory() with custom_qiskitrc(): store_credentials(credentials) # Cause all warnings to always be triggered. warnings.simplefilter("always") # Attempt overwriting. with warnings.catch_warnings(record=True) as w: store_credentials(credentials) self.assertIn('already present', str(w[0])) with no_file('Qconfig.py'), no_envs(CREDENTIAL_ENV_VARS), mock_ibmq_provider(): # Attempt overwriting. store_credentials(credentials2, overwrite=True) factory.load_account() # Ensure that the credentials are the overwritten ones. self.assertEqual(factory._credentials, credentials2)