def test_get_environment_variable_file_error(self): nonexistent_file = datafile('nonexistent') os.environ[GOOGLE_APPLICATION_CREDENTIALS] = nonexistent_file # we can't use self.assertRaisesRegexp() because it is only in Python 2.7+ try: _get_environment_variable_file() self.fail(nonexistent_file + ' should not exist.') except ApplicationDefaultCredentialsError as error: self.assertEqual('File ' + nonexistent_file + ' (pointed by ' + GOOGLE_APPLICATION_CREDENTIALS + ' environment variable) does not exist!', str(error))
def _get_project_id(self): project_id = self.args.project_id if not project_id: # try to get it from credentials credentials_filename = oauth2client._get_environment_variable_file() if not credentials_filename: credentials_filename = oauth2client._get_well_known_file() if credentials_filename: with open(credentials_filename) as file_obj: client_credentials = json.load(file_obj) project_id = client_credentials['project_id'] return project_id
def test_get_environment_variable_file(self): environment_variable_file = datafile( os.path.join('gcloud', 'application_default_credentials.json')) os.environ[GOOGLE_APPLICATION_CREDENTIALS] = environment_variable_file self.assertEqual(environment_variable_file, _get_environment_variable_file())
def test_get_environment_variable_file(self): environment_variable_file = datafile( os.path.join('gcloud', 'credentials_default.json')) os.environ[GOOGLE_CREDENTIALS_DEFAULT] = environment_variable_file self.assertEqual(environment_variable_file, _get_environment_variable_file())