Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: more fixes for rest transport #1042

Merged
merged 3 commits into from
Oct 27, 2021
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
2 changes: 1 addition & 1 deletion gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ setuptools.setup(
install_requires=(
{# TODO(dovs): remove when 1.x deprecation is complete #}
{% if 'rest' in opts.transport %}
'google-api-core[grpc] >= 2.1.0, < 3.0.0dev',
'google-api-core[grpc] >= 2.2.0, < 3.0.0dev',
{% else %}
'google-api-core[grpc] >= 1.28.0, < 3.0.0dev',
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,13 @@ def test_{{ method.name|snake_case }}_rest_pager():
req.side_effect = return_values

sample_request = {{ method.http_options[0].sample_request }}
{% for field in method.body_fields.values() %}
{% if not field.oneof or field.proto3_optional %}
{# ignore oneof fields that might conflict with sample_request #}
sample_request["{{ field.name }}"] = {{ field.mock_value }}
{% endif %}
{% endfor %}

pager = client.{{ method.name|snake_case }}(request=sample_request)

{% if method.paged_result_field.map %}
Expand Down
4 changes: 3 additions & 1 deletion gapic/utils/uri_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def sample_from_path_fields(paths: List[Tuple[str, str]]) -> Dict[Any, Any]:

for path, template in paths:
sample_value = re.sub(
r"(\*\*|\*)", lambda n: next(sample_names), template)
r"(\*\*|\*)",
lambda n: next(sample_names), template if template else '*'
)
add_field(request, path, sample_value)
return request
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
include_package_data=True,
install_requires=(
"click >= 6.7",
"google-api-core >= 2.1.0",
"google-api-core >= 2.2.0",
"googleapis-common-protos >= 1.53.0",
"grpcio >= 1.24.3",
"jinja2 >= 2.10",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/schema/wrappers/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ def test_method_http_options_generate_sample():
'id': 'projects/sample1/regions/sample2/id/sample3'}}


def test_method_http_options_generate_sample_implicit_template():
http_rule = http_pb2.HttpRule(
get='/v1/{resource.id}/stuff',
)
method = make_method('DoSomething', http_rule=http_rule)
sample = method.http_options[0].sample_request
assert json.loads(sample) == {'resource': {
'id': 'sample1'}}


def test_method_query_params():
# tests only the basic case of grpc transcoding
http_rule = http_pb2.HttpRule(
Expand Down