From dbb6fb8506b6c16ed7a99db4f764a6d398894121 Mon Sep 17 00:00:00 2001 From: Sabrina Demagny Date: Tue, 29 Oct 2024 10:51:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5(teams)=20remove=20pagination=20of?= =?UTF-8?q?=20teams=20listing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For frontend pagination is useless for teams, so we remove it. --- CHANGELOG.md | 4 ++ src/backend/core/api/viewsets.py | 1 + .../tests/teams/test_core_api_teams_list.py | 59 ++----------------- 3 files changed, 11 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f111aadc9..ddb8378f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to ## [Unreleased] +### Changed + +- 🔥(teams) remove pagination of teams listing + ### Fixed - 💚(ci) improve E2E tests #492 diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index cf8fa2a85..d99c5cc68 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -259,6 +259,7 @@ class TeamViewSet( ordering_fields = ["created_at"] ordering = ["-created_at"] queryset = models.Team.objects.all() + pagination_class = None def get_queryset(self): """Custom queryset to get user related teams.""" diff --git a/src/backend/core/tests/teams/test_core_api_teams_list.py b/src/backend/core/tests/teams/test_core_api_teams_list.py index c4aed5828..420dd59e7 100644 --- a/src/backend/core/tests/teams/test_core_api_teams_list.py +++ b/src/backend/core/tests/teams/test_core_api_teams_list.py @@ -47,60 +47,13 @@ def test_api_teams_list_authenticated(): ) assert response.status_code == HTTP_200_OK - results = response.json()["results"] + results = response.json() + assert len(results) == 5 results_id = {result["id"] for result in results} assert expected_ids == results_id -@mock.patch.object(PageNumberPagination, "get_page_size", return_value=2) -def test_api_teams_list_pagination( - _mock_page_size, -): - """Pagination should work as expected.""" - user = factories.UserFactory() - - client = APIClient() - client.force_login(user) - - team_ids = [ - str(access.team.id) - for access in factories.TeamAccessFactory.create_batch(3, user=user) - ] - - # Get page 1 - response = client.get( - "/api/v1.0/teams/", - ) - - assert response.status_code == HTTP_200_OK - content = response.json() - - assert content["count"] == 3 - assert content["next"] == "http://testserver/api/v1.0/teams/?page=2" - assert content["previous"] is None - - assert len(content["results"]) == 2 - for item in content["results"]: - team_ids.remove(item["id"]) - - # Get page 2 - response = client.get( - "/api/v1.0/teams/?page=2", - ) - - assert response.status_code == HTTP_200_OK - content = response.json() - - assert content["count"] == 3 - assert content["next"] is None - assert content["previous"] == "http://testserver/api/v1.0/teams/" - - assert len(content["results"]) == 1 - team_ids.remove(content["results"][0]["id"]) - assert team_ids == [] - - def test_api_teams_list_authenticated_distinct(): """A team with several related users should only be listed once.""" user = factories.UserFactory() @@ -118,8 +71,8 @@ def test_api_teams_list_authenticated_distinct(): assert response.status_code == HTTP_200_OK content = response.json() - assert len(content["results"]) == 1 - assert content["results"][0]["id"] == str(team.id) + assert len(content) == 1 + assert content[0]["id"] == str(team.id) def test_api_teams_order(): @@ -142,7 +95,7 @@ def test_api_teams_order(): assert response.status_code == 200 response_data = response.json() - response_team_ids = [team["id"] for team in response_data["results"]] + response_team_ids = [team["id"] for team in response_data] team_ids.reverse() assert ( @@ -171,7 +124,7 @@ def test_api_teams_order_param(): response_data = response.json() - response_team_ids = [team["id"] for team in response_data["results"]] + response_team_ids = [team["id"] for team in response_data] assert ( response_team_ids == team_ids