1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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), "<p>the body of the page</p>")
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")
|