Skip to content

Commit

Permalink
fix: paged code and templates are no longer message centric (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
software-dov authored Jul 15, 2020
1 parent 901a9ee commit 00ba77c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from typing import Any, Callable, Iterable, Sequence, Tuple
{% for method in service.methods.values() | selectattr('paged_result_field') -%}
{{ method.input.ident.python_import }}
{{ method.output.ident.python_import }}
{{ method.paged_result_field.message.ident.python_import }}
{% if not method.paged_result_field.is_primitive %}{{ method.paged_result_field.message.ident.python_import }}{% endif %}
{% endfor %}
{% endfilter -%}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ def test_{{ method.name|snake_case }}_pager():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -434,14 +434,14 @@ def test_{{ method.name|snake_case }}_pager():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand All @@ -465,7 +465,7 @@ def test_{{ method.name|snake_case }}_pager():

results = [i for i in pager]
assert len(results) == 6
assert all(isinstance(i, {{ method.paged_result_field.message.ident }})
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in results)

def test_{{ method.name|snake_case }}_pages():
Expand All @@ -481,9 +481,9 @@ def test_{{ method.name|snake_case }}_pages():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -493,14 +493,14 @@ def test_{{ method.name|snake_case }}_pages():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand Down
2 changes: 1 addition & 1 deletion gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def _ref_types(self, recursive: bool) -> Sequence[Union[MessageType, EnumType]]:

# If this message paginates its responses, it is possible
# that the individual result messages reside in a different module.
if self.paged_result_field:
if self.paged_result_field and self.paged_result_field.message:
answer.append(self.paged_result_field.message)

# Done; return the answer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence,
{% for method in service.methods.values() | selectattr('paged_result_field') -%}
{{ method.input.ident.python_import }}
{{ method.output.ident.python_import }}
{{ method.paged_result_field.message.ident.python_import }}
{% if not method.paged_result_field.is_primitive %}{{ method.paged_result_field.message.ident.python_import }}{% endif %}
{% endfor %}
{% endfilter -%}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ def test_{{ method.name|snake_case }}_pager():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -719,14 +719,14 @@ def test_{{ method.name|snake_case }}_pager():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand All @@ -750,7 +750,7 @@ def test_{{ method.name|snake_case }}_pager():

results = [i for i in pager]
assert len(results) == 6
assert all(isinstance(i, {{ method.paged_result_field.message.ident }})
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in results)

def test_{{ method.name|snake_case }}_pages():
Expand All @@ -766,9 +766,9 @@ def test_{{ method.name|snake_case }}_pages():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -778,14 +778,14 @@ def test_{{ method.name|snake_case }}_pages():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand All @@ -808,9 +808,9 @@ async def test_{{ method.name|snake_case }}_async_pager():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -820,14 +820,14 @@ async def test_{{ method.name|snake_case }}_async_pager():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand All @@ -839,7 +839,7 @@ async def test_{{ method.name|snake_case }}_async_pager():
responses.append(response)

assert len(responses) == 6
assert all(isinstance(i, {{ method.paged_result_field.message.ident }})
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in responses)

@pytest.mark.asyncio
Expand All @@ -856,9 +856,9 @@ async def test_{{ method.name|snake_case }}_async_pages():
call.side_effect = (
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='abc',
),
Expand All @@ -868,14 +868,14 @@ async def test_{{ method.name|snake_case }}_async_pages():
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
next_page_token='ghi',
),
{{ method.output.ident }}(
{{ method.paged_result_field.name }}=[
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.message.ident }}(),
{{ method.paged_result_field.type.ident }}(),
{{ method.paged_result_field.type.ident }}(),
],
),
RuntimeError,
Expand Down

0 comments on commit 00ba77c

Please sign in to comment.