|
40 | 40 | from google.cloud.devtools.containeranalysis_v1.services.container_analysis import ( |
41 | 41 | transports, |
42 | 42 | ) |
43 | | -from google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.base import ( |
44 | | - _API_CORE_VERSION, |
45 | | -) |
46 | 43 | from google.cloud.devtools.containeranalysis_v1.services.container_analysis.transports.base import ( |
47 | 44 | _GOOGLE_AUTH_VERSION, |
48 | 45 | ) |
|
55 | 52 | import google.auth |
56 | 53 |
|
57 | 54 |
|
58 | | -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: |
59 | | -# - Delete all the api-core and auth "less than" test cases |
| 55 | +# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively |
| 56 | +# through google-api-core: |
| 57 | +# - Delete the auth "less than" test cases |
60 | 58 | # - Delete these pytest markers (Make the "greater than or equal to" tests the default). |
61 | 59 | requires_google_auth_lt_1_25_0 = pytest.mark.skipif( |
62 | 60 | packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), |
|
67 | 65 | reason="This test requires google-auth >= 1.25.0", |
68 | 66 | ) |
69 | 67 |
|
70 | | -requires_api_core_lt_1_26_0 = pytest.mark.skipif( |
71 | | - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), |
72 | | - reason="This test requires google-api-core < 1.26.0", |
73 | | -) |
74 | | - |
75 | | -requires_api_core_gte_1_26_0 = pytest.mark.skipif( |
76 | | - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), |
77 | | - reason="This test requires google-api-core >= 1.26.0", |
78 | | -) |
79 | | - |
80 | 68 |
|
81 | 69 | def client_cert_source_callback(): |
82 | 70 | return b"cert bytes", b"key bytes" |
@@ -140,6 +128,18 @@ def test_container_analysis_client_from_service_account_info(client_class): |
140 | 128 | assert client.transport._host == "containeranalysis.googleapis.com:443" |
141 | 129 |
|
142 | 130 |
|
| 131 | +@pytest.mark.parametrize( |
| 132 | + "client_class", [ContainerAnalysisClient, ContainerAnalysisAsyncClient,] |
| 133 | +) |
| 134 | +def test_container_analysis_client_service_account_always_use_jwt(client_class): |
| 135 | + with mock.patch.object( |
| 136 | + service_account.Credentials, "with_always_use_jwt_access", create=True |
| 137 | + ) as use_jwt: |
| 138 | + creds = service_account.Credentials(None, None, None) |
| 139 | + client = client_class(credentials=creds) |
| 140 | + use_jwt.assert_called_with(True) |
| 141 | + |
| 142 | + |
143 | 143 | @pytest.mark.parametrize( |
144 | 144 | "client_class", [ContainerAnalysisClient, ContainerAnalysisAsyncClient,] |
145 | 145 | ) |
@@ -1627,7 +1627,6 @@ def test_container_analysis_transport_auth_adc_old_google_auth(transport_class): |
1627 | 1627 | (transports.ContainerAnalysisGrpcAsyncIOTransport, grpc_helpers_async), |
1628 | 1628 | ], |
1629 | 1629 | ) |
1630 | | -@requires_api_core_gte_1_26_0 |
1631 | 1630 | def test_container_analysis_transport_create_channel(transport_class, grpc_helpers): |
1632 | 1631 | # If credentials and host are not provided, the transport class should use |
1633 | 1632 | # ADC credentials. |
@@ -1656,79 +1655,6 @@ def test_container_analysis_transport_create_channel(transport_class, grpc_helpe |
1656 | 1655 | ) |
1657 | 1656 |
|
1658 | 1657 |
|
1659 | | -@pytest.mark.parametrize( |
1660 | | - "transport_class,grpc_helpers", |
1661 | | - [ |
1662 | | - (transports.ContainerAnalysisGrpcTransport, grpc_helpers), |
1663 | | - (transports.ContainerAnalysisGrpcAsyncIOTransport, grpc_helpers_async), |
1664 | | - ], |
1665 | | -) |
1666 | | -@requires_api_core_lt_1_26_0 |
1667 | | -def test_container_analysis_transport_create_channel_old_api_core( |
1668 | | - transport_class, grpc_helpers |
1669 | | -): |
1670 | | - # If credentials and host are not provided, the transport class should use |
1671 | | - # ADC credentials. |
1672 | | - with mock.patch.object( |
1673 | | - google.auth, "default", autospec=True |
1674 | | - ) as adc, mock.patch.object( |
1675 | | - grpc_helpers, "create_channel", autospec=True |
1676 | | - ) as create_channel: |
1677 | | - creds = ga_credentials.AnonymousCredentials() |
1678 | | - adc.return_value = (creds, None) |
1679 | | - transport_class(quota_project_id="octopus") |
1680 | | - |
1681 | | - create_channel.assert_called_with( |
1682 | | - "containeranalysis.googleapis.com:443", |
1683 | | - credentials=creds, |
1684 | | - credentials_file=None, |
1685 | | - quota_project_id="octopus", |
1686 | | - scopes=("https://www.googleapis.com/auth/cloud-platform",), |
1687 | | - ssl_credentials=None, |
1688 | | - options=[ |
1689 | | - ("grpc.max_send_message_length", -1), |
1690 | | - ("grpc.max_receive_message_length", -1), |
1691 | | - ], |
1692 | | - ) |
1693 | | - |
1694 | | - |
1695 | | -@pytest.mark.parametrize( |
1696 | | - "transport_class,grpc_helpers", |
1697 | | - [ |
1698 | | - (transports.ContainerAnalysisGrpcTransport, grpc_helpers), |
1699 | | - (transports.ContainerAnalysisGrpcAsyncIOTransport, grpc_helpers_async), |
1700 | | - ], |
1701 | | -) |
1702 | | -@requires_api_core_lt_1_26_0 |
1703 | | -def test_container_analysis_transport_create_channel_user_scopes( |
1704 | | - transport_class, grpc_helpers |
1705 | | -): |
1706 | | - # If credentials and host are not provided, the transport class should use |
1707 | | - # ADC credentials. |
1708 | | - with mock.patch.object( |
1709 | | - google.auth, "default", autospec=True |
1710 | | - ) as adc, mock.patch.object( |
1711 | | - grpc_helpers, "create_channel", autospec=True |
1712 | | - ) as create_channel: |
1713 | | - creds = ga_credentials.AnonymousCredentials() |
1714 | | - adc.return_value = (creds, None) |
1715 | | - |
1716 | | - transport_class(quota_project_id="octopus", scopes=["1", "2"]) |
1717 | | - |
1718 | | - create_channel.assert_called_with( |
1719 | | - "containeranalysis.googleapis.com:443", |
1720 | | - credentials=creds, |
1721 | | - credentials_file=None, |
1722 | | - quota_project_id="octopus", |
1723 | | - scopes=["1", "2"], |
1724 | | - ssl_credentials=None, |
1725 | | - options=[ |
1726 | | - ("grpc.max_send_message_length", -1), |
1727 | | - ("grpc.max_receive_message_length", -1), |
1728 | | - ], |
1729 | | - ) |
1730 | | - |
1731 | | - |
1732 | 1658 | @pytest.mark.parametrize( |
1733 | 1659 | "transport_class", |
1734 | 1660 | [ |
|
0 commit comments