Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#846 [Admin] Fix pagination #847

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BackEnd/administration/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def filter_is_deleted(self, queryset, name, value):

ordering = filters.OrderingFilter(
fields=(
("id", "id"),
("name", "name"),
("surname", "surname"),
("email", "email"),
Expand Down
1 change: 1 addition & 0 deletions BackEnd/administration/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class ListPagination(PageNumberPagination):
page_size_query_param = "page_size"
page_size = 20

def get_paginated_response(self, data):
return Response(
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/administration/tests/test_admin_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_get_profiles_structure_json(self):
}
]
self.assertEqual(status.HTTP_200_OK, response.status_code)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])

def test_get_profile_id_authenticated(self):
self.client.force_authenticate(self.user)
Expand Down
56 changes: 10 additions & 46 deletions BackEnd/administration/tests/test_admin_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,9 @@ def setUp(self):
AdminUserFactory.reset_sequence(1)
self.user = self.users[0]

def test_get_users_ordering_desc(self):
def test_get_users_ordering_default(self):
self.client.force_authenticate(self.user)
response = self.client.get(path="/api/admin/users/?ordering=-id")
data = [
{
"id": 3,
"email": "test3@test.com",
"name": "Test person 3",
"surname": "Test person 3 surname",
"status": {
"is_active": True,
"is_staff": True,
"is_superuser": False,
"is_deleted": False,
},
"company_name": None,
"registration_date": None,
},
{
"id": 2,
"email": "test2@test.com",
"name": "Test person 2",
"surname": "Test person 2 surname",
"status": {
"is_active": True,
"is_staff": True,
"is_superuser": False,
"is_deleted": False,
},
"company_name": None,
"registration_date": None,
},
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())

def test_get_users_ordering_asc(self):
self.client.force_authenticate(self.user)
response = self.client.get(path="/api/admin/users/?ordering=id")
response = self.client.get(path="/api/admin/users/")
data = [
{
"id": 2,
Expand Down Expand Up @@ -99,7 +63,7 @@ def test_get_users_ordering_asc(self):
},
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])

def test_get_users_filter_id_surname(self):
self.client.force_authenticate(self.user)
Expand All @@ -121,7 +85,7 @@ def test_get_users_filter_id_surname(self):
},
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])


class TestAdminUsersStatusAPITests(APITestCase):
Expand Down Expand Up @@ -166,7 +130,7 @@ def test_get_users_filter_status_active_staff(self):
},
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])

def test_get_users_filter_status_superuser_staff_active(self):
self.client.force_authenticate(self.user)
Expand All @@ -175,7 +139,7 @@ def test_get_users_filter_status_superuser_staff_active(self):
)
data = []
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])


class TestAdminUsersAPITests(APITestCase):
Expand Down Expand Up @@ -211,11 +175,11 @@ def test_get_users_authenticated(self):
}
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])

def test_get_users_filter(self):
def test_get_users(self):
self.client.force_authenticate(self.user)
response = self.client.get(path="/api/admin/users/?ordering=id")
response = self.client.get(path="/api/admin/users/")
data = [
{
"id": 2,
Expand All @@ -233,7 +197,7 @@ def test_get_users_filter(self):
}
]
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data, response.json())
self.assertEqual(data, response.data["results"])

def test_get_user_id_authenticated(self):
self.client.force_authenticate(self.user)
Expand Down
4 changes: 1 addition & 3 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class UsersListView(ListAPIView):
serializer_class = AdminUserListSerializer
filter_backends = [DjangoFilterBackend]
filterset_class = UsersFilter

def get_queryset(self):
return CustomUser.objects.select_related("profile")
queryset = CustomUser.objects.select_related("profile").order_by("id")


class UserDetailView(RetrieveUpdateDestroyAPIView):
Expand Down
Loading