|
71 | 71 | V1_DISCOVERY_URI,
|
72 | 72 | V2_DISCOVERY_URI,
|
73 | 73 | ResourceMethodParameters,
|
| 74 | + APICoreVersionError, |
74 | 75 | _fix_up_media_path_base_url,
|
75 | 76 | _fix_up_media_upload,
|
76 | 77 | _fix_up_method_description,
|
@@ -2501,170 +2502,196 @@ def test_validate_credentials_with_already_validated_credentials(self):
|
2501 | 2502 | # Calling service._validate_credentials() again returns service.credentials_validated.
|
2502 | 2503 | assert service._validate_credentials()
|
2503 | 2504 |
|
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 |
| - ) |
2516 |
| - |
2517 |
| - tasklists = tasks.tasklists() |
2518 |
| - request = tasklists.list() |
2519 |
| - |
2520 |
| - # Check that credentials are indeed verified before request. |
2521 |
| - assert tasklists._validate_credentials() |
2522 |
| - |
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 |
| - ) |
| 2505 | + def test_validate_credentials_before_api_request_success(self): |
| 2506 | + fake_universe = "foo.com" |
| 2507 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2508 | + credentials.universe_domain = fake_universe |
| 2509 | + discovery = read_datafile("tasks.json") |
| 2510 | + tasks = build_from_document( |
| 2511 | + discovery, |
| 2512 | + credentials=credentials, |
| 2513 | + client_options=google.api_core.client_options.ClientOptions( |
| 2514 | + universe_domain=fake_universe |
| 2515 | + ), |
| 2516 | + ) |
2535 | 2517 |
|
2536 |
| - # Check that credentials are verified before request. |
2537 |
| - with self.assertRaises(universe.UniverseMismatchError): |
2538 |
| - request = tasks.tasklists().list() |
| 2518 | + tasklists = tasks.tasklists() |
| 2519 | + request = tasklists.list() |
2539 | 2520 |
|
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 |
| - ) |
| 2521 | + # Check that credentials are indeed verified before request. |
| 2522 | + assert tasklists._validate_credentials() |
2553 | 2523 |
|
2554 |
| - # Check that credentials are verified before request. |
2555 |
| - with self.assertRaises(universe.UniverseMismatchError): |
2556 |
| - request = tasks.tasklists().list() |
| 2524 | + def test_validate_credentials_before_api_request_failure(self): |
| 2525 | + fake_universe = "foo.com" |
| 2526 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2527 | + credentials.universe_domain = fake_universe |
| 2528 | + discovery = read_datafile("tasks.json") |
| 2529 | + tasks = build_from_document( |
| 2530 | + discovery, |
| 2531 | + credentials=credentials, |
| 2532 | + client_options=google.api_core.client_options.ClientOptions( |
| 2533 | + universe_domain=universe.DEFAULT_UNIVERSE |
| 2534 | + ), |
| 2535 | + ) |
2557 | 2536 |
|
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") |
| 2537 | + # Check that credentials are verified before request. |
| 2538 | + with self.assertRaises(universe.UniverseMismatchError): |
| 2539 | + request = tasks.tasklists().list() |
2562 | 2540 |
|
2563 |
| - with self.assertRaises(universe.EmptyUniverseError): |
| 2541 | + def test_validate_credentials_before_another_universe_api_request_failure(self): |
| 2542 | + fake_universe = "foo.com" |
| 2543 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2544 | + credentials.universe_domain = fake_universe |
| 2545 | + another_fake_universe = "bar.com" |
| 2546 | + discovery = read_datafile("tasks.json") |
2564 | 2547 | tasks = build_from_document(
|
2565 | 2548 | discovery,
|
2566 | 2549 | credentials=credentials,
|
2567 | 2550 | client_options=google.api_core.client_options.ClientOptions(
|
2568 |
| - universe_domain="" |
| 2551 | + universe_domain=another_fake_universe |
2569 | 2552 | ),
|
2570 | 2553 | )
|
2571 | 2554 |
|
2572 |
| - def test_client_options_universe_configured_with_mtls(self): |
2573 |
| - fake_universe = "foo.com" |
2574 |
| - discovery = read_datafile("tasks.json") |
| 2555 | + # Check that credentials are verified before request. |
| 2556 | + with self.assertRaises(universe.UniverseMismatchError): |
| 2557 | + request = tasks.tasklists().list() |
2575 | 2558 |
|
2576 |
| - with self.assertRaises(MutualTLSChannelError): |
2577 |
| - with mock.patch.dict( |
2578 |
| - "os.environ", {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"} |
2579 |
| - ): |
| 2559 | + def test_client_options_with_empty_universe(self): |
| 2560 | + fake_universe = "foo.com" |
| 2561 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2562 | + discovery = read_datafile("tasks.json") |
| 2563 | + |
| 2564 | + with self.assertRaises(universe.EmptyUniverseError): |
2580 | 2565 | tasks = build_from_document(
|
2581 | 2566 | discovery,
|
| 2567 | + credentials=credentials, |
2582 | 2568 | client_options=google.api_core.client_options.ClientOptions(
|
2583 |
| - universe_domain=fake_universe |
| 2569 | + universe_domain="" |
2584 | 2570 | ),
|
2585 | 2571 | )
|
2586 | 2572 |
|
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") |
| 2573 | + def test_client_options_universe_configured_with_mtls(self): |
| 2574 | + fake_universe = "foo.com" |
| 2575 | + discovery = read_datafile("tasks.json") |
2592 | 2576 |
|
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 |
| - ) |
| 2577 | + with self.assertRaises(MutualTLSChannelError): |
| 2578 | + with mock.patch.dict( |
| 2579 | + "os.environ", {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"} |
| 2580 | + ): |
| 2581 | + tasks = build_from_document( |
| 2582 | + discovery, |
| 2583 | + client_options=google.api_core.client_options.ClientOptions( |
| 2584 | + universe_domain=fake_universe |
| 2585 | + ), |
| 2586 | + ) |
2600 | 2587 |
|
2601 |
| - assert tasks._baseUrl == fake_api_endpoint |
| 2588 | + def test_client_options_universe_configured_with_api_override(self): |
| 2589 | + fake_universe = "foo.com" |
| 2590 | + fake_api_endpoint = "https://www.bar.com/" |
| 2591 | + credentials = mock.Mock(universe_domain=fake_universe) |
| 2592 | + discovery = read_datafile("tasks.json") |
2602 | 2593 |
|
2603 |
| - def test_universe_env_var_configured_empty(self): |
2604 |
| - credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
2605 |
| - discovery = read_datafile("tasks.json") |
| 2594 | + tasks = build_from_document( |
| 2595 | + discovery, |
| 2596 | + credentials=credentials, |
| 2597 | + client_options=google.api_core.client_options.ClientOptions( |
| 2598 | + api_endpoint=fake_api_endpoint, universe_domain=fake_universe |
| 2599 | + ), |
| 2600 | + ) |
| 2601 | + |
| 2602 | + assert tasks._baseUrl == fake_api_endpoint |
| 2603 | + |
| 2604 | + def test_universe_env_var_configured_empty(self): |
| 2605 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2606 | + discovery = read_datafile("tasks.json") |
| 2607 | + |
| 2608 | + with self.assertRaises(universe.EmptyUniverseError): |
| 2609 | + with mock.patch.dict( |
| 2610 | + "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""} |
| 2611 | + ): |
| 2612 | + tasks = build_from_document( |
| 2613 | + discovery, |
| 2614 | + credentials=credentials, |
| 2615 | + ) |
| 2616 | + |
| 2617 | + def test_universe_env_var_configured_with_mtls(self): |
| 2618 | + fake_universe = "foo.com" |
| 2619 | + discovery = read_datafile("tasks.json") |
| 2620 | + |
| 2621 | + with self.assertRaises(MutualTLSChannelError): |
| 2622 | + with mock.patch.dict( |
| 2623 | + "os.environ", |
| 2624 | + { |
| 2625 | + "GOOGLE_API_USE_MTLS_ENDPOINT": "always", |
| 2626 | + "GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe, |
| 2627 | + }, |
| 2628 | + ): |
| 2629 | + tasks = build_from_document(discovery) |
| 2630 | + |
| 2631 | + def test_universe_env_var_configured_with_api_override(self): |
| 2632 | + fake_universe = "foo.com" |
| 2633 | + fake_api_endpoint = "https://www.bar.com/" |
| 2634 | + credentials = mock.Mock(universe_domain=fake_universe) |
| 2635 | + discovery = read_datafile("tasks.json") |
2606 | 2636 |
|
2607 |
| - with self.assertRaises(universe.EmptyUniverseError): |
2608 | 2637 | with mock.patch.dict(
|
2609 |
| - "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": ""} |
| 2638 | + "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe} |
2610 | 2639 | ):
|
2611 | 2640 | tasks = build_from_document(
|
2612 | 2641 | discovery,
|
2613 | 2642 | credentials=credentials,
|
| 2643 | + client_options=google.api_core.client_options.ClientOptions( |
| 2644 | + api_endpoint=fake_api_endpoint |
| 2645 | + ), |
2614 | 2646 | )
|
2615 | 2647 |
|
2616 |
| - def test_universe_env_var_configured_with_mtls(self): |
2617 |
| - fake_universe = "foo.com" |
2618 |
| - discovery = read_datafile("tasks.json") |
| 2648 | + assert tasks._baseUrl == fake_api_endpoint |
| 2649 | + |
| 2650 | + def test_universe_env_var_configured_with_client_options_universe(self): |
| 2651 | + fake_universe = "foo.com" |
| 2652 | + another_fake_universe = "bar.com" |
| 2653 | + credentials = mock.Mock(universe_domain=fake_universe) |
| 2654 | + discovery = read_datafile("tasks.json") |
2619 | 2655 |
|
2620 |
| - with self.assertRaises(MutualTLSChannelError): |
2621 | 2656 | with mock.patch.dict(
|
2622 |
| - "os.environ", |
2623 |
| - { |
2624 |
| - "GOOGLE_API_USE_MTLS_ENDPOINT": "always", |
2625 |
| - "GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe, |
2626 |
| - }, |
| 2657 | + "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe} |
2627 | 2658 | ):
|
2628 |
| - tasks = build_from_document(discovery) |
| 2659 | + tasks = build_from_document( |
| 2660 | + discovery, |
| 2661 | + credentials=credentials, |
| 2662 | + client_options=google.api_core.client_options.ClientOptions( |
| 2663 | + universe_domain=fake_universe |
| 2664 | + ), |
| 2665 | + ) |
2629 | 2666 |
|
2630 |
| - def test_universe_env_var_configured_with_api_override(self): |
| 2667 | + assert tasks._universe_domain == fake_universe |
| 2668 | + |
| 2669 | + def test_client_options_universe_with_older_version_of_api_core(self): |
2631 | 2670 | fake_universe = "foo.com"
|
2632 |
| - fake_api_endpoint = "https://www.bar.com/" |
2633 |
| - credentials = mock.Mock(universe_domain=fake_universe) |
| 2671 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2672 | + credentials.universe_domain = fake_universe |
2634 | 2673 | discovery = read_datafile("tasks.json")
|
2635 |
| - |
2636 |
| - with mock.patch.dict( |
2637 |
| - "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe} |
2638 |
| - ): |
| 2674 | + with self.assertRaises(APICoreVersionError): |
2639 | 2675 | tasks = build_from_document(
|
2640 | 2676 | discovery,
|
2641 | 2677 | credentials=credentials,
|
2642 | 2678 | client_options=google.api_core.client_options.ClientOptions(
|
2643 |
| - api_endpoint=fake_api_endpoint |
| 2679 | + universe_domain=fake_universe |
2644 | 2680 | ),
|
2645 | 2681 | )
|
2646 | 2682 |
|
2647 |
| - assert tasks._baseUrl == fake_api_endpoint |
2648 | 2683 |
|
2649 |
| - def test_universe_env_var_configured_with_client_options_universe(self): |
| 2684 | + def test_credentials_universe_with_older_version_of_api_core(self): |
2650 | 2685 | fake_universe = "foo.com"
|
2651 |
| - another_fake_universe = "bar.com" |
2652 |
| - credentials = mock.Mock(universe_domain=fake_universe) |
| 2686 | + credentials = mock.Mock(spec=google.auth.credentials.Credentials) |
| 2687 | + credentials.universe_domain = fake_universe |
2653 | 2688 | discovery = read_datafile("tasks.json")
|
2654 |
| - |
2655 |
| - with mock.patch.dict( |
2656 |
| - "os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe} |
2657 |
| - ): |
| 2689 | + with self.assertRaises(APICoreVersionError): |
2658 | 2690 | tasks = build_from_document(
|
2659 | 2691 | discovery,
|
2660 | 2692 | credentials=credentials,
|
2661 |
| - client_options=google.api_core.client_options.ClientOptions( |
2662 |
| - universe_domain=fake_universe |
2663 |
| - ), |
2664 | 2693 | )
|
2665 |
| - |
2666 |
| - assert tasks._universe_domain == fake_universe |
2667 |
| - |
| 2694 | + |
2668 | 2695 |
|
2669 | 2696 | if __name__ == "__main__":
|
2670 | 2697 | unittest.main()
|
0 commit comments