From b13c2563348741bc1aa241c35041f31b480db0cc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2017 13:35:59 +0000 Subject: Ensure the pagination arguments are present if a page was specified Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/project.py b/pagure/api/project.py index 152315e..406fc49 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -578,9 +578,6 @@ def api_projects(): 'short': short, } } - if not projects: - jsonout['projects'] = [] - return flask.jsonify(jsonout) if not short: projects = [p.to_json(api=True, public=True) for p in projects] diff --git a/tests/test_pagure_flask_api_project.py b/tests/test_pagure_flask_api_project.py index 8055ea7..784ba44 100644 --- a/tests/test_pagure_flask_api_project.py +++ b/tests/test_pagure_flask_api_project.py @@ -1300,6 +1300,34 @@ class PagureFlaskApiProjecttests(tests.Modeltests): output = self.app.get('/api/0/projects?page=99999') self.assertEqual(output.status_code, 200) + data = json.loads(output.data) + self.assertEqual( + data, + { + "args": { + "fork": None, + "namespace": None, + "owner": None, + "page": 99999, + "pattern": None, + "per_page": 20, + "short": False, + "tags": [], + "username": None + }, + "pagination": { + "first": "http://localhost/api/0/projects?per_page=20&page=1", + "last": "http://localhost/api/0/projects?per_page=20&page=1", + "next": None, + "page": 99999, + "pages": 1, + "per_page": 20, + "prev": "http://localhost/api/0/projects?per_page=20&page=99998" + }, + "projects": [], + "total_projects": 3 + } + ) def test_api_modify_project_main_admin(self): """ Test the api_modify_project method of the flask api when the