|
35 | 35 | PublishedContentFactory, |
36 | 36 | ) |
37 | 37 | from zds.utils.header_notifications import get_header_notifications |
38 | | -from zds.utils.models import Alert, Hat, Tag |
39 | | -from zds.utils.tests.factories import CategoryFactory, LicenceFactory, SubCategoryFactory |
| 38 | +from zds.utils.models import Alert, Hat |
| 39 | +from zds.utils.tests.factories import LicenceFactory, SubCategoryFactory |
40 | 40 |
|
41 | 41 | overridden_zds_app = deepcopy(settings.ZDS_APP) |
42 | 42 | overridden_zds_app["content"]["repo_private_path"] = settings.BASE_DIR / "contents-private-test" |
@@ -1599,177 +1599,6 @@ def test_obsolete(self): |
1599 | 1599 | self.assertEqual(result.status_code, 200) |
1600 | 1600 | self.assertNotContains(result, _("Ce contenu est obsolète.")) |
1601 | 1601 |
|
1602 | | - def test_list_publications(self): |
1603 | | - """Test the behavior of the publication list""" |
1604 | | - |
1605 | | - category_1 = CategoryFactory() |
1606 | | - category_2 = CategoryFactory() |
1607 | | - subcategory_1 = SubCategoryFactory(category=category_1) |
1608 | | - subcategory_2 = SubCategoryFactory(category=category_1) |
1609 | | - subcategory_3 = SubCategoryFactory(category=category_2) |
1610 | | - subcategory_4 = SubCategoryFactory(category=category_2) |
1611 | | - tag_1 = Tag(title="random") |
1612 | | - tag_1.save() |
1613 | | - |
1614 | | - tuto_p_1 = PublishedContentFactory(author_list=[self.user_author]) |
1615 | | - tuto_p_2 = PublishedContentFactory(author_list=[self.user_author]) |
1616 | | - tuto_p_3 = PublishedContentFactory(author_list=[self.user_author]) |
1617 | | - |
1618 | | - article_p_1 = PublishedContentFactory(author_list=[self.user_author], type="ARTICLE") |
1619 | | - |
1620 | | - tuto_p_1.subcategory.add(subcategory_1) |
1621 | | - tuto_p_1.subcategory.add(subcategory_2) |
1622 | | - tuto_p_1.save() |
1623 | | - |
1624 | | - tuto_p_2.subcategory.add(subcategory_1) |
1625 | | - tuto_p_2.subcategory.add(subcategory_2) |
1626 | | - tuto_p_2.save() |
1627 | | - |
1628 | | - tuto_p_3.subcategory.add(subcategory_3) |
1629 | | - tuto_p_3.save() |
1630 | | - |
1631 | | - article_p_1.subcategory.add(subcategory_4) |
1632 | | - article_p_1.tags.add(tag_1) |
1633 | | - article_p_1.save() |
1634 | | - |
1635 | | - tuto_1 = PublishedContent.objects.get(content=tuto_p_1.pk) |
1636 | | - tuto_2 = PublishedContent.objects.get(content=tuto_p_2.pk) |
1637 | | - tuto_3 = PublishedContent.objects.get(content=tuto_p_3.pk) |
1638 | | - article_1 = PublishedContent.objects.get(content=article_p_1.pk) |
1639 | | - |
1640 | | - self.assertEqual(PublishableContent.objects.filter(type="ARTICLE").count(), 1) |
1641 | | - self.assertEqual(PublishableContent.objects.filter(type="TUTORIAL").count(), 4) |
1642 | | - |
1643 | | - # 1. Publication list |
1644 | | - result = self.client.get(reverse("publication:list")) |
1645 | | - self.assertEqual(result.status_code, 200) |
1646 | | - |
1647 | | - self.assertEqual(len(result.context["last_contents"]), 5) |
1648 | | - |
1649 | | - # 2. Category page |
1650 | | - result = self.client.get(reverse("publication:category", kwargs={"slug": category_1.slug})) |
1651 | | - self.assertEqual(result.status_code, 200) |
1652 | | - |
1653 | | - self.assertEqual(len(result.context["last_contents"]), 2) |
1654 | | - |
1655 | | - pks = [x.pk for x in result.context["last_contents"]] |
1656 | | - self.assertIn(tuto_1.pk, pks) |
1657 | | - self.assertIn(tuto_2.pk, pks) |
1658 | | - |
1659 | | - result = self.client.get(reverse("publication:category", kwargs={"slug": category_2.slug})) |
1660 | | - self.assertEqual(result.status_code, 200) |
1661 | | - |
1662 | | - self.assertEqual(len(result.context["last_contents"]), 2) |
1663 | | - |
1664 | | - pks = [x.pk for x in result.context["last_contents"]] |
1665 | | - self.assertIn(tuto_3.pk, pks) |
1666 | | - self.assertIn(article_1.pk, pks) |
1667 | | - |
1668 | | - # 3. Subcategory page |
1669 | | - result = self.client.get( |
1670 | | - reverse("publication:subcategory", kwargs={"slug_category": category_1.slug, "slug": subcategory_1.slug}) |
1671 | | - ) |
1672 | | - |
1673 | | - self.assertEqual(result.status_code, 200) |
1674 | | - |
1675 | | - self.assertEqual(len(result.context["last_contents"]), 2) |
1676 | | - |
1677 | | - pks = [x.pk for x in result.context["last_contents"]] |
1678 | | - self.assertIn(tuto_1.pk, pks) |
1679 | | - self.assertIn(tuto_2.pk, pks) |
1680 | | - |
1681 | | - result = self.client.get( |
1682 | | - reverse("publication:subcategory", kwargs={"slug_category": category_1.slug, "slug": subcategory_2.slug}) |
1683 | | - ) |
1684 | | - |
1685 | | - self.assertEqual(result.status_code, 200) |
1686 | | - |
1687 | | - self.assertEqual(len(result.context["last_contents"]), 2) |
1688 | | - |
1689 | | - pks = [x.pk for x in result.context["last_contents"]] |
1690 | | - self.assertIn(tuto_1.pk, pks) |
1691 | | - self.assertIn(tuto_2.pk, pks) |
1692 | | - |
1693 | | - result = self.client.get( |
1694 | | - reverse("publication:subcategory", kwargs={"slug_category": category_2.slug, "slug": subcategory_3.slug}) |
1695 | | - ) |
1696 | | - |
1697 | | - self.assertEqual(result.status_code, 200) |
1698 | | - |
1699 | | - self.assertEqual(len(result.context["last_contents"]), 1) |
1700 | | - |
1701 | | - pks = [x.pk for x in result.context["last_contents"]] |
1702 | | - self.assertIn(tuto_3.pk, pks) |
1703 | | - |
1704 | | - result = self.client.get( |
1705 | | - reverse("publication:subcategory", kwargs={"slug_category": category_2.slug, "slug": subcategory_4.slug}) |
1706 | | - ) |
1707 | | - |
1708 | | - self.assertEqual(result.status_code, 200) |
1709 | | - |
1710 | | - self.assertEqual(len(result.context["last_contents"]), 1) |
1711 | | - |
1712 | | - pks = [x.pk for x in result.context["last_contents"]] |
1713 | | - self.assertIn(article_1.pk, pks) |
1714 | | - |
1715 | | - # 4. Final page and filters |
1716 | | - result = self.client.get(reverse("publication:list") + f"?category={category_1.slug}") |
1717 | | - self.assertEqual(result.status_code, 200) |
1718 | | - |
1719 | | - self.assertEqual(len(result.context["filtered_contents"]), 2) |
1720 | | - pks = [x.pk for x in result.context["filtered_contents"]] |
1721 | | - self.assertIn(tuto_1.pk, pks) |
1722 | | - self.assertIn(tuto_2.pk, pks) |
1723 | | - |
1724 | | - # filter by category and type |
1725 | | - result = self.client.get(reverse("publication:list") + f"?category={category_2.slug}") |
1726 | | - self.assertEqual(result.status_code, 200) |
1727 | | - |
1728 | | - self.assertEqual(len(result.context["filtered_contents"]), 2) |
1729 | | - pks = [x.pk for x in result.context["filtered_contents"]] |
1730 | | - self.assertIn(tuto_3.pk, pks) |
1731 | | - self.assertIn(article_1.pk, pks) |
1732 | | - |
1733 | | - # filter by subcategory |
1734 | | - result = self.client.get(reverse("publication:list") + f"?subcategory={subcategory_1.slug}") |
1735 | | - self.assertEqual(result.status_code, 200) |
1736 | | - |
1737 | | - self.assertEqual(len(result.context["filtered_contents"]), 2) |
1738 | | - pks = [x.pk for x in result.context["filtered_contents"]] |
1739 | | - self.assertIn(tuto_1.pk, pks) |
1740 | | - self.assertIn(tuto_2.pk, pks) |
1741 | | - |
1742 | | - # filter by subcategory and type |
1743 | | - result = self.client.get(reverse("publication:list") + f"?subcategory={subcategory_3.slug}") |
1744 | | - self.assertEqual(result.status_code, 200) |
1745 | | - |
1746 | | - self.assertEqual(len(result.context["filtered_contents"]), 1) |
1747 | | - pks = [x.pk for x in result.context["filtered_contents"]] |
1748 | | - self.assertIn(tuto_3.pk, pks) |
1749 | | - |
1750 | | - # filter by tag |
1751 | | - result = self.client.get(reverse("publication:list") + f"?tag={tag_1.slug}" + "&type=article") |
1752 | | - self.assertEqual(result.status_code, 200) |
1753 | | - |
1754 | | - self.assertEqual(len(result.context["filtered_contents"]), 1) |
1755 | | - pks = [x.pk for x in result.context["filtered_contents"]] |
1756 | | - self.assertIn(article_1.pk, pks) |
1757 | | - |
1758 | | - # 5. Everything else results in 404 |
1759 | | - wrong_urls = [ |
1760 | | - # not existing (sub)categories, types or tags with slug "xxx" |
1761 | | - reverse("publication:list") + "?category=xxx", |
1762 | | - reverse("publication:list") + "?subcategory=xxx", |
1763 | | - reverse("publication:list") + "?tag=xxx", |
1764 | | - reverse("publication:category", kwargs={"slug": "xxx"}), |
1765 | | - reverse("publication:subcategory", kwargs={"slug_category": category_2.slug, "slug": "xxx"}), |
1766 | | - # subcategory_1 does not belong to category_2: |
1767 | | - reverse("publication:subcategory", kwargs={"slug_category": category_2.slug, "slug": subcategory_1.slug}), |
1768 | | - ] |
1769 | | - |
1770 | | - for url in wrong_urls: |
1771 | | - self.assertEqual(self.client.get(url).status_code, 404, msg=url) |
1772 | | - |
1773 | 1602 | def test_article_previous_link(self): |
1774 | 1603 | """Test the behaviour of the article previous link.""" |
1775 | 1604 |
|
|
0 commit comments