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: add field headers for other http verbs #443

Merged
merged 11 commits into from
Jun 9, 2020
16 changes: 15 additions & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,22 @@ def client_output(self):
def field_headers(self) -> Sequence[str]:
"""Return the field headers defined for this method."""
http = self.options.Extensions[annotations_pb2.http]

pattern = re.compile(r'\{([a-z][\w\d_.]+)=')

if http.get:
return tuple(re.findall(r'\{([a-z][\w\d_.]+)=', http.get))
return tuple(pattern.findall(http.get))
elif http.put:
return tuple(pattern.findall(http.put))
elif http.post:
return tuple(pattern.findall(http.post))
elif http.delete:
return tuple(pattern.findall(http.delete))
elif http.patch:
return tuple(pattern.findall(http.patch))
elif http.custom.path:
return tuple(pattern.findall(http.custom.path))
busunkim96 marked this conversation as resolved.
Show resolved Hide resolved

return ()

@utils.cached_property
Expand Down
34 changes: 33 additions & 1 deletion tests/unit/schema/wrappers/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,44 @@ def test_method_field_headers_none():
assert isinstance(method.field_headers, collections.abc.Sequence)


def test_method_field_headers_present():
def test_method_field_headers_present_get():
http_rule = http_pb2.HttpRule(get='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)


def test_method_field_headers_present_put():
http_rule = http_pb2.HttpRule(put='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)


def test_method_field_headers_present_post():
http_rule = http_pb2.HttpRule(post='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)


def test_method_field_headers_present_delete():
http_rule = http_pb2.HttpRule(delete='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)


def test_method_field_headers_present_patch():
http_rule = http_pb2.HttpRule(patch='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)
busunkim96 marked this conversation as resolved.
Show resolved Hide resolved


def test_method_field_headers_present_custom():
custom_pattern = http_pb2.CustomHttpPattern(kind='custom',
path='/v1/{parent=projects/*}/topics')
http_rule = http_pb2.HttpRule(custom=custom_pattern)
method = make_method('DoSomething', http_rule=http_rule)
assert method.field_headers == ('parent',)


def test_method_idempotent_yes():
http_rule = http_pb2.HttpRule(get='/v1/{parent=projects/*}/topics')
method = make_method('DoSomething', http_rule=http_rule)
Expand Down