From 7facf744fc9c917727938dc4ccbb2a37818ea8db Mon Sep 17 00:00:00 2001 From: Kinuax Date: Sat, 22 Jan 2022 20:44:48 +0100 Subject: [PATCH] Update docs and tests regarding pagination of empty resources --- docs/features.rst | 4 ++-- docs/quickstart.rst | 5 +++++ eve/tests/methods/get.py | 10 ++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index df43ea229..5ae4c6afb 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -100,8 +100,8 @@ These additional fields are automatically handled by the API (clients don't need to provide them when adding/editing resources). The ``_meta`` field provides pagination data and will only be there if -:ref:`Pagination` has been enabled (it is by default) and there is at least one -document being returned. The ``_links`` list provides HATEOAS_ directives. +:ref:`Pagination` has been enabled (it is by default). The ``_links`` list +provides HATEOAS_ directives. .. _subresources: diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 4dceff3ba..265a6e448 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -91,6 +91,11 @@ Try requesting ``people`` now: "href": "/", "title": "home" } + }, + "_meta": { + "max_results": 25, + "page": 1, + "total": 0 } } diff --git a/eve/tests/methods/get.py b/eve/tests/methods/get.py index 2fb52e963..86ad7a2f8 100644 --- a/eve/tests/methods/get.py +++ b/eve/tests/methods/get.py @@ -27,6 +27,8 @@ def test_get_empty_resource(self): self.assertResourceLink(links, self.empty_resource) self.assertHomeLink(links) + self.assertPagination(response, 1, 0, 25) + def test_get_max_results(self): maxr = 10 response, status = self.get(self.known_resource, "?max_results=%d" % maxr) @@ -381,7 +383,7 @@ def test_get_projection(self): self.assertTrue(r[self.app.config["DATE_CREATED"]] != self.epoch) def test_get_static_projection(self): - """ Test that static projections are honoured """ + """Test that static projections are honoured""" response, status = self.get(self.different_resource) self.assert200(status) @@ -1279,21 +1281,21 @@ def test_get_idfield_doesnt_exist(self): self.assert200(status) def test_get_invalid_idfield_cors(self): - """ test that #381 is fixed. """ + """test that #381 is fixed.""" request = "/%s/badid" % self.known_resource self.app.config["X_DOMAINS"] = "*" r = self.test_client.get(request, headers=[("Origin", "test.com")]) self.assert404(r.status_code) def test_get_invalid_where_syntax(self): - """ test that 'where' syntax with unknown '$' operator returns 400. """ + """test that 'where' syntax with unknown '$' operator returns 400.""" response, status = self.get( self.known_resource, '?where={"field": {"$foo": "bar"}}' ) self.assert400(status) def test_get_invalid_sort_syntax(self): - """ test that invalid sort syntax returns a 400 """ + """test that invalid sort syntax returns a 400""" response, status = self.get(self.known_resource, '?sort=[("prog":1)]') self.assert400(status) response, status = self.get(self.known_resource, '?sort="firstname"')