Skip to content

Commit

Permalink
Add DeepArchiveIndexPageTest.test_get_context_with_page_number
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jul 18, 2023
1 parent 75ae2ba commit e5a4045
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions magazine/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def setUp(self) -> None:
self.deep_archive_index = DeepArchiveIndexPage(title="Deep Archive Index")
self.magazine_index.add_child(instance=self.deep_archive_index)

self.publication_years = [2019, 2020, 2021]
self.publication_years = list(range(1920, 1930))

self.archive_issues = []

Expand All @@ -614,10 +614,12 @@ def test_get_context(self) -> None:
# Call the get_context method
context = self.deep_archive_index.get_context(request)

archive_items_per_page = 9

# Check that the context includes the archive issues
self.assertQuerySetEqual( # type: ignore
context["archive_issues"],
ArchiveIssue.objects.all(),
self.archive_issues[:archive_items_per_page],
transform=lambda x: x, # Transform the objects to compare them directly
ordered=False, # The order of the results is not important
)
Expand All @@ -627,3 +629,20 @@ def test_get_context(self) -> None:
list(context["publication_years"]),
self.publication_years,
)

def test_get_context_with_page_number(self) -> None:
# Create a mock request with 'page' as a GET parameter
request = self.factory.get("/?page=2")

# Call the get_context method
context = self.deep_archive_index.get_context(request)

archive_items_per_page = 9

# Check that the context includes the archive issues
self.assertQuerySetEqual( # type: ignore
context["archive_issues"],
self.archive_issues[archive_items_per_page:],
transform=lambda x: x, # Transform the objects to compare them directly
ordered=False, # The order of the results is not important
)

0 comments on commit e5a4045

Please sign in to comment.