from django.test import TestCase from pages.models import Page class PageModelTest(TestCase): def setUp(self): self.page = Page( title="Test Page", meta_description="The meta desc", body_markdown="the body of the page", ) self.page.save() self.pathpage = Page( title="Test Page", meta_description="The meta desc", body_markdown="the body of the page", path="test-path", ) self.pathpage.save() def test_string_representation(self): self.assertEqual(str(self.page), "Test Page") self.assertEqual(str(self.page.slug), "test-page") self.assertEqual(str(self.page.body_markdown), "the body of the page") self.assertEqual(str(self.page.body_html), "

the body of the page

") self.assertEqual(str(self.page.meta_description), "The meta desc") self.assertEqual(self.page.path, None) def test_get_absolute_url(self): """Absolute URL should return /page """ self.assertEqual(str(self.page.get_absolute_url()), "/test-page") def test_path_get_absolute_url(self): """Absolute URL with a path should return /path/page """ self.assertEqual(str(self.pathpage.get_absolute_url()), "/test-path/test-page")