from django.test import TestCase from django.urls import reverse from django.utils import timezone from apps.pages.models import BlogPost, HomepageSection class HomeViewTest(TestCase): def test_home_returns_200(self): response = self.client.get(reverse("pages:home")) self.assertEqual(response.status_code, 200) def test_home_uses_correct_template(self): response = self.client.get(reverse("pages:home")) self.assertTemplateUsed(response, "pages/home.html") def test_section_description_renders_markdown_and_html(self): HomepageSection.objects.create( section_type=HomepageSection.TYPE_FEATURES, title="Rich section", description="**Formatted** content", description_format="markdown", ) response = self.client.get(reverse("pages:home")) self.assertContains(response, "Formatted") class AboutViewTest(TestCase): def test_about_returns_200(self): response = self.client.get(reverse("pages:about")) self.assertEqual(response.status_code, 200) def test_about_uses_correct_template(self): response = self.client.get(reverse("pages:about")) self.assertTemplateUsed(response, "pages/about.html") class BlogViewTest(TestCase): def setUp(self): self.post = BlogPost.objects.create( title="Research update", slug="research-update", excerpt="A short summary.", content="## Results\n\n**Promising** findings.", content_format="markdown", status=BlogPost.STATUS_PUBLISHED, published_at=timezone.now(), ) def test_blog_list_and_detail_render_published_post(self): listing = self.client.get(reverse("pages:blog_list")) detail = self.client.get(self.post.get_absolute_url()) self.assertContains(listing, self.post.title) self.assertContains(detail, "