#5112 Fix broken pagination of group API
Merged 3 years ago by pingou. Opened 3 years ago by lbrabec.
lbrabec/pagure fix/group_pagination  into  master

file modified
+1 -1
@@ -278,7 +278,7 @@ 

          )

          query_start = (page - 1) * per_page

          query_limit = per_page

-         page_projects = group_projects[query_start:query_limit]

+         page_projects = group_projects[query_start : query_start + query_limit]

  

          output["total_projects"] = projects_cnt

          output["pagination"] = pagination_metadata

@@ -719,6 +719,57 @@ 

          data["pagination"]["last"] = "http://localhost..."

          self.assertDictEqual(data, exp)

  

+     def test_api_view_group_w_projects_and_acl_pagination(self):

+         """

+         Tests the pagination for the api_view_group method

+         """

+ 

+         project = pagure.lib.query._get_project(self.session, "test2")

+         msg = pagure.lib.query.add_group_to_project(

+             session=self.session,

+             project=project,

+             new_group="some_group",

+             user="pingou",

+             access="commit",

+         )

+         self.session.commit()

+         self.assertEqual(msg, "Group access updated")

+ 

+         project_another = pagure.lib.query._get_project(self.session, "test")

+         msg = pagure.lib.query.add_group_to_project(

+             session=self.session,

+             project=project_another,

+             new_group="some_group",

+             user="pingou",

+             access="commit",

+         )

+         self.session.commit()

+         self.assertEqual(msg, "Group added")

+ 

+         tests.create_tokens(self.session)

+ 

+         headers = {"Authorization": "token aaabbbcccddd"}

+         output = self.app.get(

+             "/api/0/group/some_group?projects=1&per_page=1", headers=headers

+         )

+         self.assertEqual(output.status_code, 200)

+ 

+         data = json.loads(output.get_data(as_text=True))

+         projects = [project["name"] for project in data["projects"]]

+ 

+         # Test the result we've got from the first page out of two

+         assert projects == ["test"]

+ 

+         output_last = self.app.get(data["pagination"]["next"], headers=headers)

+         self.assertEqual(output_last.status_code, 200)

+         data_last = json.loads(output_last.get_data(as_text=True))

+ 

+         projects.extend([project["name"] for project in data_last["projects"]])

+ 

+         # Note that pagure sorts projects alphabetically, so we're comparing

+         # a different order that was the order of requests

+         assert projects == ["test", "test2"]

+ 

  

  if __name__ == "__main__":

      unittest.main(verbosity=2)

Should we look at the tests for this?

1 new commit added

  • Add basic pagination test for group API
3 years ago

1 new commit added

  • Add basic pagination test for group API
3 years ago

@pingou I've added a basic test for this. It fails without the fix applied, passes with the fix. Can you take a look? It might be enough of a test imo as it's currently broken, but it's up to you ofc :)

Should we do a first assert here? It'll highlight the difference between page 1 and 2

2 new commits added

  • Add basic pagination test for group API
  • Fix broken pagination of group API
3 years ago

Should we do a first assert here? It'll highlight the difference between page 1 and 2

Done, I've left the complete assert in the end too, I can change that if you want?

1 new commit added

  • Code styling issue fix around group api pagination fix
3 years ago

The tests passed, the el7 failure is un-related to this PR so let's get this in :)

Pull-Request has been merged by pingou

3 years ago