Skip to content

Commit

Permalink
🔥(teams) remove pagination of teams listing
Browse files Browse the repository at this point in the history
For frontend pagination is useless for teams,
so we remove it.
  • Loading branch information
sdemagny committed Oct 30, 2024
1 parent 2bbed8d commit dbb6fb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 53 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [Unreleased]

### Changed

- 🔥(teams) remove pagination of teams listing

### Fixed

- 💚(ci) improve E2E tests #492
Expand Down
1 change: 1 addition & 0 deletions src/backend/core/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
59 changes: 6 additions & 53 deletions src/backend/core/tests/teams/test_core_api_teams_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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():
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dbb6fb8

Please sign in to comment.