def test_file_credentials_non_google(self, mock_storage): with infra_libs.temporary_directory() as temp_dir: path = os.path.join(temp_dir, 'foo') with open(path, 'w') as fh: json.dump({}, fh) ret = monitors.FileCredentials(path).create(['bar']) mock_storage.assert_called_once_with(path) mock_storage.return_value.get.assert_called_once_with() self.assertEqual(ret, mock_storage.return_value.get.return_value)
def test_file_credentials_google(self, mock_from_stream): with infra_libs.temporary_directory() as temp_dir: path = os.path.join(temp_dir, 'foo') with open(path, 'w') as fh: json.dump({'type': 'blah'}, fh) ret = monitors.FileCredentials(path).create(['bar']) mock_from_stream.assert_called_once_with(path) creds = mock_from_stream.return_value creds.create_scoped.assert_called_once_with(['bar']) self.assertEqual(ret, creds.create_scoped.return_value)