Skip to content

Commit

Permalink
Merge branch 'master' into fix-415
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rossi authored May 13, 2020
2 parents 7036625 + a69ffd2 commit 8eb85a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion google/cloud/ndb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ def fetch_page_async(self, page_size, **kwargs):
results.append(result.entity())
cursor = result.cursor

more = results and (
more = bool(results) and (
iterator._more_results_after_limit or iterator.probably_has_next()
)
raise tasklets.Return(results, cursor, more)
Expand Down
4 changes: 4 additions & 0 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

s.replace(".kokoro/build.sh", """(export PROJECT_ID=.*)""", """\g<1>
# Configure Local Redis to be used
export REDIS_CACHE_URL=redis://localhost
redis-server &
# Some system tests require indexes. Use gcloud to create them.
gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS --project=$PROJECT_ID
gcloud --quiet --verbosity=debug datastore indexes create tests/system/index.yaml
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,36 @@ def has_next_async(self):
raw=True,
)

@staticmethod
@pytest.mark.usefixtures("in_context")
@mock.patch("google.cloud.ndb._datastore_query")
def test_fetch_page_no_results(_datastore_query):
class DummyQueryIterator:
_more_results_after_limit = True

def __init__(self):
self.items = []

def has_next_async(self):
return utils.future_result(bool(self.items))

_datastore_query.iterate.return_value = DummyQueryIterator()
query = query_module.Query()
query.filters = mock.Mock(
_multiquery=False, _post_filters=mock.Mock(return_value=False),
)
results, cursor, more = query.fetch_page(5)
assert results == []
assert cursor is None
assert more is False

_datastore_query.iterate.assert_called_once_with(
query_module.QueryOptions(
filters=query.filters, project="testing", limit=5
),
raw=True,
)

@staticmethod
@pytest.mark.usefixtures("in_context")
@mock.patch("google.cloud.ndb._datastore_query")
Expand Down

0 comments on commit 8eb85a5

Please sign in to comment.