-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert collection pagination test to pytest
- Loading branch information
Showing
1 changed file
with
31 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,35 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
import pytest | ||
|
||
from filingcabinet.models import CollectionDirectory, CollectionDocument | ||
|
||
from . import DocumentCollectionFactory, DocumentFactory, UserFactory | ||
|
||
|
||
class DocumentCollectionDetailViewPaginationTest(TestCase): | ||
def setUp(self): | ||
self.user = UserFactory.create() | ||
|
||
def test_documentcollection_pagination(self): | ||
collection = DocumentCollectionFactory(user=self.user) | ||
for i in range(100): | ||
directory = CollectionDirectory( | ||
name=f"Directory {i}", | ||
user=self.user, | ||
collection=collection, | ||
) | ||
CollectionDirectory.add_root(instance=directory) | ||
|
||
for _ in range(100): | ||
document = DocumentFactory() | ||
CollectionDocument.objects.create( | ||
collection=collection, | ||
document=document, | ||
) | ||
|
||
url = reverse("api:documentcollection-detail", kwargs={"pk": collection.pk}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 200) | ||
# Directories are not paginated, because there is no other endpoint to query them | ||
self.assertEqual(len(response.json()["directories"]), 100) | ||
|
||
# Document are paginated, because we have a seperate endpoint to query them | ||
self.assertEqual(len(response.json()["documents"]), 50) | ||
from . import DocumentCollectionFactory, DocumentFactory | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_documentcollection_pagination(client, dummy_user): | ||
collection = DocumentCollectionFactory(user=dummy_user) | ||
for i in range(100): | ||
directory = CollectionDirectory( | ||
name=f"Directory {i}", | ||
user=dummy_user, | ||
collection=collection, | ||
) | ||
CollectionDirectory.add_root(instance=directory) | ||
|
||
for _ in range(100): | ||
document = DocumentFactory() | ||
CollectionDocument.objects.create( | ||
collection=collection, | ||
document=document, | ||
) | ||
|
||
url = reverse("api:documentcollection-detail", kwargs={"pk": collection.pk}) | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
# Directories are not paginated, because there is no other endpoint to query them | ||
assert len(response.json()["directories"]) == 100 | ||
|
||
# Document are paginated, because we have a seperate endpoint to query them | ||
assert len(response.json()["documents"]) == 50 |