from django.test import TestCase, override_settings
from django.urls import reverse

from pages.models import Article, HomePage


@override_settings(USE_I18N=False)
class PageViewTest(TestCase):
    @classmethod
    def setUpTestData(cls):
        print("\nTest page views")
        # Set up non-modified objects used by all test methods
        HomePage.objects.create(title="Title")
        Article.objects.create(title="First", date="2022-04-09")

    def test_homepage_view(self):
        response = self.client.get(reverse("home"))
        self.assertEqual(response.status_code, 200)
        print("\n-Test Homepage status 200")
        self.assertTemplateUsed(response, "pages/home.html")
        print("\n-Test Homepage template")

    def test_no_homepage(self):
        HomePage.objects.all().delete()
        response = self.client.get(reverse("home"))
        self.assertEqual(response.status_code, 404)
        print("\n-Test Homepage status 404")

    def test_article_template(self):
        response = self.client.get(
            reverse(
                "pages:article_detail",
                kwargs={"year": 2022, "month": 4, "day": 9, "slug": "first"},
            )
        )
        self.assertEqual(response.status_code, 200)
        print("\n-Test Article status 200")
        self.assertTemplateUsed(response, "pages/article_detail.html")
        print("\n-Test Article template")

[((7, 1, 7, 34), 'django.test.override_settings', 'override_settings', (), '', False, 'from django.test import TestCase, override_settings\n'), ((13, 8, 13, 46), 'pages.models.HomePage.objects.create', 'HomePage.objects.create', (), '', False, 'from pages.models import Article, HomePage\n'), ((14, 8, 14, 64), 'pages.models.Article.objects.create', 'Article.objects.create', (), '', False, 'from pages.models import Article, HomePage\n'), ((17, 35, 17, 50), 'django.urls.reverse', 'reverse', ({(17, 43, 17, 49): '"""home"""'}, {}), "('home')", False, 'from django.urls import reverse\n'), ((25, 35, 25, 50), 'django.urls.reverse', 'reverse', ({(25, 43, 25, 49): '"""home"""'}, {}), "('home')", False, 'from django.urls import reverse\n'), ((31, 12, 34, 13), 'django.urls.reverse', 'reverse', (), '', False, 'from django.urls import reverse\n'), ((24, 8, 24, 30), 'pages.models.HomePage.objects.all', 'HomePage.objects.all', ({}, {}), '()', False, 'from pages.models import Article, HomePage\n')]