Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}


Expand All @@ -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 %}


Expand Down Expand Up @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}


Expand All @@ -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 %}


Expand Down Expand Up @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", [
Expand All @@ -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():
Expand Down Expand Up @@ -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())
Expand Down
Loading