Skip to content

Commit 6d25555

Browse files
committed
fix: add compatibility with older versions of api-core
1 parent b81c559 commit 6d25555

File tree

1 file changed

+131
-131
lines changed

1 file changed

+131
-131
lines changed

tests/test_discovery.py

Lines changed: 131 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,9 +2340,9 @@ def test_get_media(self):
23402340
self.assertEqual(b"standing in for media", response)
23412341

23422342

2343-
if HAS_UNIVERSE:
23442343

2345-
class Universe(unittest.TestCase):
2344+
class Universe(unittest.TestCase):
2345+
if HAS_UNIVERSE:
23462346
def test_validate_credentials_with_no_client_options(self):
23472347
http = build_http()
23482348
discovery = read_datafile("zoo.json")
@@ -2501,169 +2501,169 @@ def test_validate_credentials_with_already_validated_credentials(self):
25012501
# Calling service._validate_credentials() again returns service.credentials_validated.
25022502
assert service._validate_credentials()
25032503

2504-
def test_validate_credentials_before_api_request_success(self):
2505-
fake_universe = "foo.com"
2506-
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2507-
credentials.universe_domain = fake_universe
2508-
discovery = read_datafile("tasks.json")
2509-
tasks = build_from_document(
2510-
discovery,
2511-
credentials=credentials,
2512-
client_options=google.api_core.client_options.ClientOptions(
2513-
universe_domain=fake_universe
2514-
),
2515-
)
2504+
def test_validate_credentials_before_api_request_success(self):
2505+
fake_universe = "foo.com"
2506+
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2507+
credentials.universe_domain = fake_universe
2508+
discovery = read_datafile("tasks.json")
2509+
tasks = build_from_document(
2510+
discovery,
2511+
credentials=credentials,
2512+
client_options=google.api_core.client_options.ClientOptions(
2513+
universe_domain=fake_universe
2514+
),
2515+
)
25162516

2517-
tasklists = tasks.tasklists()
2518-
request = tasklists.list()
2517+
tasklists = tasks.tasklists()
2518+
request = tasklists.list()
25192519

2520-
# Check that credentials are indeed verified before request.
2521-
assert tasklists._validate_credentials()
2520+
# Check that credentials are indeed verified before request.
2521+
assert tasklists._validate_credentials()
25222522

2523-
def test_validate_credentials_before_api_request_failure(self):
2524-
fake_universe = "foo.com"
2525-
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2526-
credentials.universe_domain = fake_universe
2527-
discovery = read_datafile("tasks.json")
2528-
tasks = build_from_document(
2529-
discovery,
2530-
credentials=credentials,
2531-
client_options=google.api_core.client_options.ClientOptions(
2532-
universe_domain=universe.DEFAULT_UNIVERSE
2533-
),
2534-
)
2523+
def test_validate_credentials_before_api_request_failure(self):
2524+
fake_universe = "foo.com"
2525+
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2526+
credentials.universe_domain = fake_universe
2527+
discovery = read_datafile("tasks.json")
2528+
tasks = build_from_document(
2529+
discovery,
2530+
credentials=credentials,
2531+
client_options=google.api_core.client_options.ClientOptions(
2532+
universe_domain=universe.DEFAULT_UNIVERSE
2533+
),
2534+
)
25352535

2536-
# Check that credentials are verified before request.
2537-
with self.assertRaises(universe.UniverseMismatchError):
2538-
request = tasks.tasklists().list()
2536+
# Check that credentials are verified before request.
2537+
with self.assertRaises(universe.UniverseMismatchError):
2538+
request = tasks.tasklists().list()
25392539

2540-
def test_validate_credentials_before_another_universe_api_request_failure(self):
2541-
fake_universe = "foo.com"
2542-
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2543-
credentials.universe_domain = fake_universe
2544-
another_fake_universe = "bar.com"
2545-
discovery = read_datafile("tasks.json")
2540+
def test_validate_credentials_before_another_universe_api_request_failure(self):
2541+
fake_universe = "foo.com"
2542+
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2543+
credentials.universe_domain = fake_universe
2544+
another_fake_universe = "bar.com"
2545+
discovery = read_datafile("tasks.json")
2546+
tasks = build_from_document(
2547+
discovery,
2548+
credentials=credentials,
2549+
client_options=google.api_core.client_options.ClientOptions(
2550+
universe_domain=another_fake_universe
2551+
),
2552+
)
2553+
2554+
# Check that credentials are verified before request.
2555+
with self.assertRaises(universe.UniverseMismatchError):
2556+
request = tasks.tasklists().list()
2557+
2558+
def test_client_options_with_empty_universe(self):
2559+
fake_universe = "foo.com"
2560+
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2561+
discovery = read_datafile("tasks.json")
2562+
2563+
with self.assertRaises(universe.EmptyUniverseError):
25462564
tasks = build_from_document(
25472565
discovery,
25482566
credentials=credentials,
25492567
client_options=google.api_core.client_options.ClientOptions(
2550-
universe_domain=another_fake_universe
2568+
universe_domain=""
25512569
),
25522570
)
25532571

2554-
# Check that credentials are verified before request.
2555-
with self.assertRaises(universe.UniverseMismatchError):
2556-
request = tasks.tasklists().list()
2557-
2558-
def test_client_options_with_empty_universe(self):
2559-
fake_universe = "foo.com"
2560-
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2561-
discovery = read_datafile("tasks.json")
2572+
def test_client_options_universe_configured_with_mtls(self):
2573+
fake_universe = "foo.com"
2574+
discovery = read_datafile("tasks.json")
25622575

2563-
with self.assertRaises(universe.EmptyUniverseError):
2576+
with self.assertRaises(MutualTLSChannelError):
2577+
with mock.patch.dict(
2578+
"os.environ", {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}
2579+
):
25642580
tasks = build_from_document(
25652581
discovery,
2566-
credentials=credentials,
25672582
client_options=google.api_core.client_options.ClientOptions(
2568-
universe_domain=""
2583+
universe_domain=fake_universe
25692584
),
25702585
)
25712586

2572-
def test_client_options_universe_configured_with_mtls(self):
2573-
fake_universe = "foo.com"
2574-
discovery = read_datafile("tasks.json")
2575-
2576-
with self.assertRaises(MutualTLSChannelError):
2577-
with mock.patch.dict(
2578-
"os.environ", {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}
2579-
):
2580-
tasks = build_from_document(
2581-
discovery,
2582-
client_options=google.api_core.client_options.ClientOptions(
2583-
universe_domain=fake_universe
2584-
),
2585-
)
2586-
2587-
def test_client_options_universe_configured_with_api_override(self):
2588-
fake_universe = "foo.com"
2589-
fake_api_endpoint = "https://www.bar.com/"
2590-
credentials = mock.Mock(universe_domain=fake_universe)
2591-
discovery = read_datafile("tasks.json")
2592-
2593-
tasks = build_from_document(
2594-
discovery,
2595-
credentials=credentials,
2596-
client_options=google.api_core.client_options.ClientOptions(
2597-
api_endpoint=fake_api_endpoint, universe_domain=fake_universe
2598-
),
2599-
)
2600-
2601-
assert tasks._baseUrl == fake_api_endpoint
2602-
2603-
def test_universe_env_var_configured_empty(self):
2604-
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2605-
discovery = read_datafile("tasks.json")
2606-
2607-
with self.assertRaises(universe.EmptyUniverseError):
2608-
with mock.patch.dict(
2609-
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""}
2610-
):
2611-
tasks = build_from_document(
2612-
discovery,
2613-
credentials=credentials,
2614-
)
2587+
def test_client_options_universe_configured_with_api_override(self):
2588+
fake_universe = "foo.com"
2589+
fake_api_endpoint = "https://www.bar.com/"
2590+
credentials = mock.Mock(universe_domain=fake_universe)
2591+
discovery = read_datafile("tasks.json")
26152592

2616-
def test_universe_env_var_configured_with_mtls(self):
2617-
fake_universe = "foo.com"
2618-
discovery = read_datafile("tasks.json")
2593+
tasks = build_from_document(
2594+
discovery,
2595+
credentials=credentials,
2596+
client_options=google.api_core.client_options.ClientOptions(
2597+
api_endpoint=fake_api_endpoint, universe_domain=fake_universe
2598+
),
2599+
)
26192600

2620-
with self.assertRaises(MutualTLSChannelError):
2621-
with mock.patch.dict(
2622-
"os.environ",
2623-
{
2624-
"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
2625-
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe,
2626-
},
2627-
):
2628-
tasks = build_from_document(discovery)
2601+
assert tasks._baseUrl == fake_api_endpoint
26292602

2630-
def test_universe_env_var_configured_with_api_override(self):
2631-
fake_universe = "foo.com"
2632-
fake_api_endpoint = "https://www.bar.com/"
2633-
credentials = mock.Mock(universe_domain=fake_universe)
2634-
discovery = read_datafile("tasks.json")
2603+
def test_universe_env_var_configured_empty(self):
2604+
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
2605+
discovery = read_datafile("tasks.json")
26352606

2607+
with self.assertRaises(universe.EmptyUniverseError):
26362608
with mock.patch.dict(
2637-
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe}
2609+
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""}
26382610
):
26392611
tasks = build_from_document(
26402612
discovery,
26412613
credentials=credentials,
2642-
client_options=google.api_core.client_options.ClientOptions(
2643-
api_endpoint=fake_api_endpoint
2644-
),
26452614
)
26462615

2647-
assert tasks._baseUrl == fake_api_endpoint
2648-
2649-
def test_universe_env_var_configured_with_client_options_universe(self):
2650-
fake_universe = "foo.com"
2651-
another_fake_universe = "bar.com"
2652-
credentials = mock.Mock(universe_domain=fake_universe)
2653-
discovery = read_datafile("tasks.json")
2616+
def test_universe_env_var_configured_with_mtls(self):
2617+
fake_universe = "foo.com"
2618+
discovery = read_datafile("tasks.json")
26542619

2620+
with self.assertRaises(MutualTLSChannelError):
26552621
with mock.patch.dict(
2656-
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe}
2622+
"os.environ",
2623+
{
2624+
"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
2625+
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe,
2626+
},
26572627
):
2658-
tasks = build_from_document(
2659-
discovery,
2660-
credentials=credentials,
2661-
client_options=google.api_core.client_options.ClientOptions(
2662-
universe_domain=fake_universe
2663-
),
2664-
)
2628+
tasks = build_from_document(discovery)
2629+
2630+
def test_universe_env_var_configured_with_api_override(self):
2631+
fake_universe = "foo.com"
2632+
fake_api_endpoint = "https://www.bar.com/"
2633+
credentials = mock.Mock(universe_domain=fake_universe)
2634+
discovery = read_datafile("tasks.json")
2635+
2636+
with mock.patch.dict(
2637+
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe}
2638+
):
2639+
tasks = build_from_document(
2640+
discovery,
2641+
credentials=credentials,
2642+
client_options=google.api_core.client_options.ClientOptions(
2643+
api_endpoint=fake_api_endpoint
2644+
),
2645+
)
2646+
2647+
assert tasks._baseUrl == fake_api_endpoint
2648+
2649+
def test_universe_env_var_configured_with_client_options_universe(self):
2650+
fake_universe = "foo.com"
2651+
another_fake_universe = "bar.com"
2652+
credentials = mock.Mock(universe_domain=fake_universe)
2653+
discovery = read_datafile("tasks.json")
2654+
2655+
with mock.patch.dict(
2656+
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe}
2657+
):
2658+
tasks = build_from_document(
2659+
discovery,
2660+
credentials=credentials,
2661+
client_options=google.api_core.client_options.ClientOptions(
2662+
universe_domain=fake_universe
2663+
),
2664+
)
26652665

2666-
assert tasks._universe_domain == fake_universe
2666+
assert tasks._universe_domain == fake_universe
26672667

26682668

26692669
if __name__ == "__main__":

0 commit comments

Comments
 (0)