summaryrefslogtreecommitdiff
path: root/app/pages/tests
diff options
context:
space:
mode:
Diffstat (limited to 'app/pages/tests')
-rw-r--r--app/pages/tests/__init__.py0
-rw-r--r--app/pages/tests/test_models.py36
-rw-r--r--app/pages/tests/test_views.py27
3 files changed, 63 insertions, 0 deletions
diff --git a/app/pages/tests/__init__.py b/app/pages/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/pages/tests/__init__.py
diff --git a/app/pages/tests/test_models.py b/app/pages/tests/test_models.py
new file mode 100644
index 0000000..2722430
--- /dev/null
+++ b/app/pages/tests/test_models.py
@@ -0,0 +1,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")
diff --git a/app/pages/tests/test_views.py b/app/pages/tests/test_views.py
new file mode 100644
index 0000000..c771a29
--- /dev/null
+++ b/app/pages/tests/test_views.py
@@ -0,0 +1,27 @@
+from django.test import RequestFactory, TestCase
+from django.contrib import auth
+
+from pages.models import Page
+
+User = auth.get_user_model()
+
+
+class PageViewTest(TestCase):
+ def setUp(self):
+ # Every test needs access to the request factory.
+ self.factory = RequestFactory()
+ self.page = Page(
+ title="Test Page",
+ meta_description="The meta desc",
+ body_markdown="the body of the page",
+ )
+ self.page.save()
+
+ def test_non_existent_page(self):
+ """A non-existent staticflatpage raises a 404."""
+ response = self.client.get('/no_such_page/')
+ self.assertEqual(response.status_code, 404)
+
+ def test_detail_view(self):
+ response = self.client.get(self.page.get_absolute_url())
+ self.assertEqual(response.status_code, 200)