-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #772 from WesternFriend/magazine-tests
Magazine tests
- Loading branch information
Showing
4 changed files
with
195 additions
and
53 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
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
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
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 +1,104 @@ | ||
# Create your tests here. | ||
import datetime | ||
from django.test import TestCase | ||
from wagtail.models import Page, Site | ||
from home.models import HomePage | ||
from .models import ( | ||
MagazineDepartmentIndexPage, | ||
MagazineDepartment, | ||
MagazineIssue, | ||
MagazineIndexPage, | ||
MagazineArticle, | ||
) | ||
|
||
|
||
class MagazineIssueTest(TestCase): | ||
def setUp(self) -> None: | ||
site_root = Page.objects.get(id=2) | ||
|
||
self.home_page = HomePage(title="Home") | ||
site_root.add_child(instance=self.home_page) | ||
|
||
Site.objects.all().update(root_page=self.home_page) | ||
|
||
self.magazine_index = MagazineIndexPage(title="Magazine") | ||
self.home_page.add_child(instance=self.magazine_index) | ||
|
||
self.magazine_issue = MagazineIssue( | ||
title="Issue 1", | ||
issue_number=1, | ||
publication_date="2020-01-01", | ||
) | ||
|
||
self.magazine_department_index = MagazineDepartmentIndexPage( | ||
title="Departments", | ||
) | ||
self.magazine_index.add_child(instance=self.magazine_department_index) | ||
self.magazine_department_one = MagazineDepartment( | ||
title="Department 1", | ||
) | ||
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_two, | ||
is_featured=True, | ||
), | ||
) | ||
self.magazine_article_two = self.magazine_issue.add_child( | ||
instance=MagazineArticle( | ||
title="Article 2", | ||
department=self.magazine_department_one, | ||
is_featured=False, | ||
), | ||
) | ||
|
||
def test_featured_articles(self) -> None: | ||
"""Test that the featured_articles property returns the correct | ||
articles.""" | ||
self.assertEqual( | ||
list(self.magazine_issue.featured_articles), | ||
[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.""" | ||
self.assertEqual( | ||
self.magazine_issue.publication_end_date, | ||
datetime.date(2020, 2, 1), | ||
) | ||
|
||
def test_get_sitemap_urls(self) -> None: | ||
"""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"], | ||
) |