Skip to content

Commit 0ba68e0

Browse files
authored
AAP-41842 Add UT for pagination (#745)
1 parent 9d38d09 commit 0ba68e0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test_app/tests/resource_registry/test_resources_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ def test_resources_delete(django_user_model):
5151
assert not Resource.objects.filter(name=user.username, object_id=user.pk, content_type=ContentType.objects.get_for_model(user).pk).exists()
5252

5353

54+
def test_resources_pagination(admin_api_client, django_user_model):
55+
"""Test that pagination does not cause missing or duplicated records."""
56+
resources_url = get_relative_url("resource-list")
57+
users_created = []
58+
for i in range(110):
59+
user = django_user_model.objects.create(username=f"resuser{i}")
60+
users_created.append(user.username)
61+
62+
page_content = []
63+
i = 0
64+
while True:
65+
i += 1
66+
resp = admin_api_client.get(f"{resources_url}?page={i}")
67+
if "results" in resp.data:
68+
page_content.append(resp.data["results"])
69+
else:
70+
break
71+
72+
all_records = [x["name"] for y in page_content for x in y if x["resource_type"] == "shared.user" and x["name"].startswith('resuser')]
73+
assert len(all_records) == len(users_created)
74+
assert set(all_records) == set(users_created)
75+
76+
# Activitystream has ordering by id
77+
activitystream_url = get_relative_url("activitystream-list")
78+
activity = admin_api_client.get(activitystream_url)
79+
assert int(activity.data["results"][-1]["id"]) + 1 == int(activity.data["results"][-2]["id"])
80+
81+
5482
def test_resources_delete_api(admin_api_client, django_user_model):
5583
"""Test that resources can be correctly deleted via the API."""
5684
user = django_user_model.objects.create(username="foo")

0 commit comments

Comments
 (0)