Skip to content

Commit

Permalink
Test articles_by_department
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie committed Jul 13, 2023
1 parent e2fe6ed commit 2ce79d7
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions magazine/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,27 @@ def setUp(self) -> None:
title="Departments",
)
self.magazine_index.add_child(instance=self.magazine_department_index)
self.magazine_department = MagazineDepartment(
self.magazine_department_one = MagazineDepartment(
title="Department 1",
)
self.magazine_department_index.add_child(instance=self.magazine_department)
self.magazine_department_two = MagazineDepartment(
title="Department 2",
)

self.magazine_department_index.add_child(instance=self.magazine_department_one)
self.magazine_department_index.add_child(instance=self.magazine_department_two)
self.magazine_index.add_child(instance=self.magazine_issue)
self.magazine_article_one = self.magazine_issue.add_child(
instance=MagazineArticle(
title="Article 1",
department=self.magazine_department,
department=self.magazine_department_two,
is_featured=True,
),
)
self.magazine_article_two = self.magazine_issue.add_child(
instance=MagazineArticle(
title="Article 2",
department=self.magazine_department,
department=self.magazine_department_one,
is_featured=False,
),
)
Expand All @@ -62,6 +66,17 @@ def test_featured_articles(self) -> None:
[self.magazine_article_one],
)

def test_articles_by_department(self) -> None:
"""Test that the articles_by_department property returns the correct
articles."""
self.assertEqual(
list(self.magazine_issue.articles_by_department),
[
self.magazine_article_two,
self.magazine_article_one,
],
)

def test_publication_end_date(self) -> None:
"""Test that the publication_end_date property returns the correct
date."""
Expand All @@ -70,10 +85,20 @@ def test_publication_end_date(self) -> None:
datetime.date(2020, 2, 1),
)

def test_get_context(self) -> None:
# Here you would add tests for the get_context method.
pass

def test_get_sitemap_urls(self) -> None:
# Here you would add tests for the get_sitemap_urls method.
pass
"""Validate the output of get_sitemap_urls."""

expected_last_mod = None
expected_location_contains = "/magazine/issue-1/"

sitemap_urls = self.magazine_issue.get_sitemap_urls()

self.assertEqual(len(sitemap_urls), 1)
self.assertEqual(
sitemap_urls[0]["lastmod"],
expected_last_mod,
)
self.assertIn(
expected_location_contains,
sitemap_urls[0]["location"],
)

0 comments on commit 2ce79d7

Please sign in to comment.