Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from google.protobuf import json_format
import json
import math
import pytest
from collections.abc import Sequence, Mapping
from google.api_core import api_core_version
from proto.marshal.rules.dates import DurationRule, TimestampRule
from proto.marshal.rules import wrappers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,18 @@ def test_{{ method_name }}_pager(transport_name: str = "grpc"):

results = list(pager)
assert len(results) == 6
{% if method.paged_result_field.type.ident|string == 'struct_pb2.ListValue' %}
assert all(isinstance(i, Sequence)
for i in results)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Struct' %}
assert all(isinstance(i, Mapping)
for i in results)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Value' %}
assert all(True for i in results)
{% else %}
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in results)
{% endif %}
{% endif %}
def test_{{ method_name }}_pages(transport_name: str = "grpc"):
client = {{ service.client_name }}(
Expand Down Expand Up @@ -913,9 +923,19 @@ async def test_{{ method_name }}_async_pager():
assert async_pager.get('a') is None
assert isinstance(async_pager.get('h'), {{ method.paged_result_field.type.fields.get('value').ident }})
{% else %}
{% if method.paged_result_field.type.ident|string == 'struct_pb2.ListValue' %}
assert all(isinstance(i, Sequence)
for i in responses)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Struct' %}
assert all(isinstance(i, Mapping)
for i in responses)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Value' %}
assert all(True for i in responses)
{% else %}
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in responses)
{% endif %}
{% endif %}


@pytest.mark.asyncio
Expand Down Expand Up @@ -1412,9 +1432,19 @@ def test_{{ method_name }}_rest_pager(transport: str = 'rest'):
assert pager.get('a') is None
assert isinstance(pager.get('h'), {{ method.paged_result_field.type.fields.get('value').ident }})
{% else %}
{% if method.paged_result_field.type.ident|string == 'struct_pb2.ListValue' %}
assert all(isinstance(i, Sequence)
for i in results)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Struct' %}
assert all(isinstance(i, Mapping)
for i in results)
{% elif method.paged_result_field.type.ident|string == 'struct_pb2.Value' %}
assert all(True for i in results)
{% else %}
assert all(isinstance(i, {{ method.paged_result_field.type.ident }})
for i in results)
{% endif %}
{% endif %}

pages = list(client.{{ method_name }}(request=sample_request).pages)
for page_, token in zip(pages, ['abc','def','ghi', '']):
Expand Down
Loading