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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds more context to error message. #340

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions google/api_core/path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def transcode(http_options, **request_kwargs):
]
path_args = {field: get_field(request_kwargs, field) for field in path_fields}
request["uri"] = expand(uri_template, **path_args)

# Remove fields used in uri path from request
leftovers = copy.deepcopy(request_kwargs)
for path_field in path_fields:
Expand All @@ -297,4 +296,8 @@ def transcode(http_options, **request_kwargs):
request["method"] = http_option["method"]
return request

raise ValueError("Request obj does not match any template")
raise ValueError(
"Request {} does not match any URL path template in available HttpRule's {}".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Request {} does not match any URL path template in available HttpRule's {}".format(
"Request {} does not match any URL path template in available HttpRules {}".format(

request_kwargs, [opt["uri"] for opt in http_options]
)
)
2 changes: 1 addition & 1 deletion tests/unit/test_path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def test_transcode_with_additional_bindings(
[[["get", "/v1/{name}", ""]], {"name": "first/last"}],
[[["get", "/v1/{name=mr/*/*}", ""]], {"name": "first/last"}],
[[["post", "/v1/{name}", "data"]], {"name": "first/last"}],
[[["post", "/v1/{first_name}", "data"]], {"last_name": "last"}],
],
)
def test_transcode_fails(http_options, request_kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you have this test check the exception string?

https://docs.pytest.org/en/6.2.x/assert.html#assertions-about-expected-exceptions

Expand All @@ -385,5 +386,4 @@ def helper_test_transcode(http_options_list, expected_result_list):
}
if expected_result_list[2]:
expected_result["body"] = expected_result_list[2]

return (http_options, expected_result)