fix: add more context to error message. (#340)
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
diff --git a/google/api_core/path_template.py b/google/api_core/path_template.py
index 41fbd4f..b6284c8 100644
--- a/google/api_core/path_template.py
+++ b/google/api_core/path_template.py
@@ -270,7 +270,6 @@
]
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:
@@ -297,4 +296,8 @@
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(
+ request_kwargs, [opt["uri"] for opt in http_options]
+ )
+ )
diff --git a/tests/unit/test_path_template.py b/tests/unit/test_path_template.py
index 2c5216e..c12b35f 100644
--- a/tests/unit/test_path_template.py
+++ b/tests/unit/test_path_template.py
@@ -362,6 +362,7 @@
[[["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):
@@ -385,5 +386,4 @@
}
if expected_result_list[2]:
expected_result["body"] = expected_result_list[2]
-
return (http_options, expected_result)