diff --git a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index ec91ca41b5..ae21c130d8 100644 --- a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -85,20 +85,32 @@ def test__get_default_mtls_endpoint(): assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - {{ service.client_name }}, +@pytest.mark.parametrize("client_class,transport_name", [ + {% if 'grpc' in opts.transport %} + ({{ service.client_name }}, "grpc"), + {% endif %} + {% if 'rest' in opts.transport %} + ({{ service.client_name }}, "rest"), + {% endif %} ]) -def test_{{ service.client_name|snake_case }}_from_service_account_info(client_class): +def test_{{ service.client_name|snake_case }}_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) {% if service.host %} - assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + assert client.transport._host == ( + '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://{{ service.host }}' + {% endif %} + ) {% endif %} @@ -122,23 +134,35 @@ def test_{{ service.client_name|snake_case }}_service_account_always_use_jwt(tra use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - {{ service.client_name }}, +@pytest.mark.parametrize("client_class,transport_name", [ + {% if 'grpc' in opts.transport %} + ({{ service.client_name }}, "grpc"), + {% endif %} + {% if 'rest' in opts.transport %} + ({{ service.client_name }}, "rest"), + {% endif %} ]) -def test_{{ service.client_name|snake_case }}_from_service_account_file(client_class): +def test_{{ service.client_name|snake_case }}_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) {% if service.host %} - assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + assert client.transport._host == ( + '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://{{ service.host }}' + {% endif %} + ) {% endif %} @@ -1853,23 +1877,53 @@ def test_{{ service.name|snake_case }}_rest_lro_client(): {%- endif %} {% endif %} {# rest #} -def test_{{ service.name|snake_case }}_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + {% if 'grpc' in opts.transport %} + "grpc", + {% endif %} + {% if 'rest' in opts.transport %} + "rest", + {% endif %} +]) +def test_{{ service.name|snake_case }}_host_no_port(transport_name): {% with host = (service.host|default('localhost', true)).split(':')[0] %} client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='{{ host }}'), + transport=transport_name, + ) + assert client.transport._host == ( + '{{ host }}:443' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://{{ host }}' + {% endif %} ) - assert client.transport._host == '{{ host }}:443' {% endwith %} -def test_{{ service.name|snake_case }}_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + {% if 'grpc' in opts.transport %} + "grpc", + {% endif %} + {% if 'rest' in opts.transport %} + "rest", + {% endif %} +]) +def test_{{ service.name|snake_case }}_host_with_port(transport_name): {% with host = (service.host|default('localhost', true)).split(':')[0] %} client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='{{ host }}:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + '{{ host }}:8000' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://{{ host }}:8000' + {% endif %} ) - assert client.transport._host == '{{ host }}:8000' {% endwith %} {% if 'grpc' in opts.transport %} diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 3e400cdd9c..1981b30a39 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -89,23 +89,33 @@ def test__get_default_mtls_endpoint(): assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - {{ service.client_name }}, +@pytest.mark.parametrize("client_class,transport_name", [ {% if 'grpc' in opts.transport %} - {{ service.async_client_name }}, + ({{ service.client_name }}, "grpc"), + ({{ service.async_client_name }}, "grpc_asyncio"), + {% endif %} + {% if 'rest' in opts.transport %} + ({{ service.client_name }}, "rest"), {% endif %} ]) -def test_{{ service.client_name|snake_case }}_from_service_account_info(client_class): +def test_{{ service.client_name|snake_case }}_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) {% if service.host %} - assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + assert client.transport._host == ( + '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://{{ service.host }}' + {% endif %} + ) {% endif %} @@ -130,26 +140,36 @@ def test_{{ service.client_name|snake_case }}_service_account_always_use_jwt(tra use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - {{ service.client_name }}, +@pytest.mark.parametrize("client_class,transport_name", [ {% if 'grpc' in opts.transport %} - {{ service.async_client_name }}, + ({{ service.client_name }}, "grpc"), + ({{ service.async_client_name }}, "grpc_asyncio"), + {% endif %} + {% if 'rest' in opts.transport %} + ({{ service.client_name }}, "rest"), {% endif %} ]) -def test_{{ service.client_name|snake_case }}_from_service_account_file(client_class): +def test_{{ service.client_name|snake_case }}_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) {% if service.host %} - assert client.transport._host == '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + assert client.transport._host == ( + '{{ service.host }}{% if ":" not in service.host %}:443{% endif %}' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else + 'https://{{ service.host }}' + {% endif %} + ) {% endif %} @@ -2323,23 +2343,54 @@ def test_{{ service.name|snake_case }}_rest_lro_client(): {% endif %} {# rest #} -def test_{{ service.name|snake_case }}_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + {% if 'grpc' in opts.transport %} + "grpc", + "grpc_asyncio", + {% endif %} + {% if 'rest' in opts.transport %} + "rest", + {% endif %} +]) +def test_{{ service.name|snake_case }}_host_no_port(transport_name): {% with host = (service.host|default('localhost', true)).split(':')[0] %} client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='{{ host }}'), + transport=transport_name, + ) + assert client.transport._host == ( + '{{ host }}:443' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://{{ host }}' + {% endif %} ) - assert client.transport._host == '{{ host }}:443' {% endwith %} - -def test_{{ service.name|snake_case }}_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + {% if 'grpc' in opts.transport %} + "grpc", + "grpc_asyncio", + {% endif %} + {% if 'rest' in opts.transport %} + "rest", + {% endif %} +]) +def test_{{ service.name|snake_case }}_host_with_port(transport_name): {% with host = (service.host|default('localhost', true)).split(':')[0] %} client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='{{ host }}:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + '{{ host }}:8000' + {% if 'rest' in opts.transport %} + if transport_name in ['grpc', 'grpc_asyncio'] + else 'https://{{ host }}:8000' + {% endif %} ) - assert client.transport._host == '{{ host }}:8000' {% endwith %} {% if 'grpc' in opts.transport %} diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index 3fe3b8fa14..b211ce806d 100644 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -76,20 +76,22 @@ def test__get_default_mtls_endpoint(): assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - AssetServiceClient, - AssetServiceAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (AssetServiceClient, "grpc"), + (AssetServiceAsyncClient, "grpc_asyncio"), ]) -def test_asset_service_client_from_service_account_info(client_class): +def test_asset_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'cloudasset.googleapis.com:443' + assert client.transport._host == ( + 'cloudasset.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -108,23 +110,25 @@ def test_asset_service_client_service_account_always_use_jwt(transport_class, tr use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - AssetServiceClient, - AssetServiceAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (AssetServiceClient, "grpc"), + (AssetServiceAsyncClient, "grpc_asyncio"), ]) -def test_asset_service_client_from_service_account_file(client_class): +def test_asset_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'cloudasset.googleapis.com:443' + assert client.transport._host == ( + 'cloudasset.googleapis.com:443' + ) def test_asset_service_client_get_transport_class(): @@ -3866,20 +3870,33 @@ def test_asset_service_grpc_transport_client_cert_source_for_mtls( ) -def test_asset_service_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_asset_service_host_no_port(transport_name): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='cloudasset.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'cloudasset.googleapis.com:443' ) - assert client.transport._host == 'cloudasset.googleapis.com:443' - -def test_asset_service_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_asset_service_host_with_port(transport_name): client = AssetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='cloudasset.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'cloudasset.googleapis.com:8000' ) - assert client.transport._host == 'cloudasset.googleapis.com:8000' def test_asset_service_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) diff --git a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index ec644b8726..d357ec3600 100644 --- a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -67,20 +67,22 @@ def test__get_default_mtls_endpoint(): assert IAMCredentialsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - IAMCredentialsClient, - IAMCredentialsAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (IAMCredentialsClient, "grpc"), + (IAMCredentialsAsyncClient, "grpc_asyncio"), ]) -def test_iam_credentials_client_from_service_account_info(client_class): +def test_iam_credentials_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'iamcredentials.googleapis.com:443' + assert client.transport._host == ( + 'iamcredentials.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -99,23 +101,25 @@ def test_iam_credentials_client_service_account_always_use_jwt(transport_class, use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - IAMCredentialsClient, - IAMCredentialsAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (IAMCredentialsClient, "grpc"), + (IAMCredentialsAsyncClient, "grpc_asyncio"), ]) -def test_iam_credentials_client_from_service_account_file(client_class): +def test_iam_credentials_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'iamcredentials.googleapis.com:443' + assert client.transport._host == ( + 'iamcredentials.googleapis.com:443' + ) def test_iam_credentials_client_get_transport_class(): @@ -1796,20 +1800,33 @@ def test_iam_credentials_grpc_transport_client_cert_source_for_mtls( ) -def test_iam_credentials_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_iam_credentials_host_no_port(transport_name): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='iamcredentials.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'iamcredentials.googleapis.com:443' ) - assert client.transport._host == 'iamcredentials.googleapis.com:443' - -def test_iam_credentials_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_iam_credentials_host_with_port(transport_name): client = IAMCredentialsClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='iamcredentials.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'iamcredentials.googleapis.com:8000' ) - assert client.transport._host == 'iamcredentials.googleapis.com:8000' def test_iam_credentials_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index 01f0c72415..9a818be449 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -68,20 +68,22 @@ def test__get_default_mtls_endpoint(): assert ConfigServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - ConfigServiceV2Client, - ConfigServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (ConfigServiceV2Client, "grpc"), + (ConfigServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_config_service_v2_client_from_service_account_info(client_class): +def test_config_service_v2_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -100,23 +102,25 @@ def test_config_service_v2_client_service_account_always_use_jwt(transport_class use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - ConfigServiceV2Client, - ConfigServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (ConfigServiceV2Client, "grpc"), + (ConfigServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_config_service_v2_client_from_service_account_file(client_class): +def test_config_service_v2_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) def test_config_service_v2_client_get_transport_class(): @@ -6258,20 +6262,33 @@ def test_config_service_v2_grpc_transport_client_cert_source_for_mtls( ) -def test_config_service_v2_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_config_service_v2_host_no_port(transport_name): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:443' ) - assert client.transport._host == 'logging.googleapis.com:443' - -def test_config_service_v2_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_config_service_v2_host_with_port(transport_name): client = ConfigServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:8000' ) - assert client.transport._host == 'logging.googleapis.com:8000' def test_config_service_v2_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 63816c158c..de5b117537 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -74,20 +74,22 @@ def test__get_default_mtls_endpoint(): assert LoggingServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - LoggingServiceV2Client, - LoggingServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (LoggingServiceV2Client, "grpc"), + (LoggingServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_logging_service_v2_client_from_service_account_info(client_class): +def test_logging_service_v2_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -106,23 +108,25 @@ def test_logging_service_v2_client_service_account_always_use_jwt(transport_clas use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - LoggingServiceV2Client, - LoggingServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (LoggingServiceV2Client, "grpc"), + (LoggingServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_logging_service_v2_client_from_service_account_file(client_class): +def test_logging_service_v2_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) def test_logging_service_v2_client_get_transport_class(): @@ -2346,20 +2350,33 @@ def test_logging_service_v2_grpc_transport_client_cert_source_for_mtls( ) -def test_logging_service_v2_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_logging_service_v2_host_no_port(transport_name): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:443' ) - assert client.transport._host == 'logging.googleapis.com:443' - -def test_logging_service_v2_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_logging_service_v2_host_with_port(transport_name): client = LoggingServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:8000' ) - assert client.transport._host == 'logging.googleapis.com:8000' def test_logging_service_v2_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 058a7be554..07fb89958b 100644 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -72,20 +72,22 @@ def test__get_default_mtls_endpoint(): assert MetricsServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - MetricsServiceV2Client, - MetricsServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (MetricsServiceV2Client, "grpc"), + (MetricsServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_metrics_service_v2_client_from_service_account_info(client_class): +def test_metrics_service_v2_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -104,23 +106,25 @@ def test_metrics_service_v2_client_service_account_always_use_jwt(transport_clas use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - MetricsServiceV2Client, - MetricsServiceV2AsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (MetricsServiceV2Client, "grpc"), + (MetricsServiceV2AsyncClient, "grpc_asyncio"), ]) -def test_metrics_service_v2_client_from_service_account_file(client_class): +def test_metrics_service_v2_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'logging.googleapis.com:443' + assert client.transport._host == ( + 'logging.googleapis.com:443' + ) def test_metrics_service_v2_client_get_transport_class(): @@ -2199,20 +2203,33 @@ def test_metrics_service_v2_grpc_transport_client_cert_source_for_mtls( ) -def test_metrics_service_v2_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_metrics_service_v2_host_no_port(transport_name): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:443' ) - assert client.transport._host == 'logging.googleapis.com:443' - -def test_metrics_service_v2_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_metrics_service_v2_host_with_port(transport_name): client = MetricsServiceV2Client( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='logging.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'logging.googleapis.com:8000' ) - assert client.transport._host == 'logging.googleapis.com:8000' def test_metrics_service_v2_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index dacb2f205d..8675180642 100644 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -73,20 +73,22 @@ def test__get_default_mtls_endpoint(): assert CloudRedisClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ - CloudRedisClient, - CloudRedisAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (CloudRedisClient, "grpc"), + (CloudRedisAsyncClient, "grpc_asyncio"), ]) -def test_cloud_redis_client_from_service_account_info(client_class): +def test_cloud_redis_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_info') as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'redis.googleapis.com:443' + assert client.transport._host == ( + 'redis.googleapis.com:443' + ) @pytest.mark.parametrize("transport_class,transport_name", [ @@ -105,23 +107,25 @@ def test_cloud_redis_client_service_account_always_use_jwt(transport_class, tran use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ - CloudRedisClient, - CloudRedisAsyncClient, +@pytest.mark.parametrize("client_class,transport_name", [ + (CloudRedisClient, "grpc"), + (CloudRedisAsyncClient, "grpc_asyncio"), ]) -def test_cloud_redis_client_from_service_account_file(client_class): +def test_cloud_redis_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object(service_account.Credentials, 'from_service_account_file') as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json("dummy/file/path.json", transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == 'redis.googleapis.com:443' + assert client.transport._host == ( + 'redis.googleapis.com:443' + ) def test_cloud_redis_client_get_transport_class(): @@ -3191,20 +3195,33 @@ def test_cloud_redis_grpc_transport_client_cert_source_for_mtls( ) -def test_cloud_redis_host_no_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_cloud_redis_host_no_port(transport_name): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='redis.googleapis.com'), + transport=transport_name, + ) + assert client.transport._host == ( + 'redis.googleapis.com:443' ) - assert client.transport._host == 'redis.googleapis.com:443' - -def test_cloud_redis_host_with_port(): +@pytest.mark.parametrize("transport_name", [ + "grpc", + "grpc_asyncio", +]) +def test_cloud_redis_host_with_port(transport_name): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions(api_endpoint='redis.googleapis.com:8000'), + transport=transport_name, + ) + assert client.transport._host == ( + 'redis.googleapis.com:8000' ) - assert client.transport._host == 'redis.googleapis.com:8000' def test_cloud_redis_grpc_transport_channel(): channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials())