-
Notifications
You must be signed in to change notification settings - Fork 69
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
Changes from all commits
5bb7d30
6c8aeeb
797da8f
78359ca
85ca6c9
f569911
224d81a
38e8711
afd742a
85f9699
8ed787d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,25 +258,33 @@ def test_{{ method.name|snake_case }}(transport: str = 'grpc'): | |
{% endfor %} | ||
{% endif %} | ||
|
||
{% if method.field_headers %} | ||
{% if method.field_headers and not method.client_streaming %} | ||
def test_{{ method.name|snake_case }}_field_headers(): | ||
client = {{ service.client_name }}( | ||
credentials=credentials.AnonymousCredentials(), | ||
) | ||
) | ||
|
||
# Any value that is part of the HTTP/1.1 URI should be sent as | ||
# a field header. Set these to a non-empty value. | ||
request = {{ method.input.ident }}( | ||
{%- for field_header in method.field_headers %} | ||
{{ field_header }}='{{ field_header }}/value', | ||
{%- endfor %} | ||
) | ||
request = {{ method.input.ident }}() | ||
|
||
{%- for field_header in method.field_headers %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tweaking this slightly for field headers like |
||
request.{{ field_header }} = '{{ field_header }}/value' | ||
{%- endfor %} | ||
|
||
# Mock the actual call within the gRPC stub, and fake the request. | ||
with mock.patch.object( | ||
type(client._transport.{{ method.name|snake_case }}), | ||
'__call__') as call: | ||
{% if method.void -%} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-pasted from the unit test below this. |
||
call.return_value = None | ||
{% elif method.lro -%} | ||
call.return_value = operations_pb2.Operation(name='operations/op') | ||
{% elif method.server_streaming -%} | ||
call.return_value = iter([{{ method.output.ident }}()]) | ||
{% else -%} | ||
call.return_value = {{ method.output.ident }}() | ||
{% endif %} | ||
client.{{ method.name|snake_case }}(request) | ||
|
||
# Establish that the underlying gRPC stub method was called. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this for a failing showcase test (see streaming method in proto and failing test).
Not sure if this is the right call though. What's the correct way to handle metadata/headers for streaming methods? @software-dov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that headers for streaming methods don't make a lot of sense because they're not tightly bound to http semantics. If that's not correct, then I think we would need to ask someone who knows better.