website/website/common/tests/test_views.py
Jake Howard 7026aca934
Add account links to footer
Putting them in the navbar is too crowded.
2022-09-02 09:28:35 +01:00

56 lines
1.8 KiB
Python

from django.test import SimpleTestCase, TestCase, override_settings
from django.urls import reverse
class Error404PageTestCase(TestCase):
url = reverse("404")
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertContains(response, "<h1>There's nothing here!</h1>", html=True)
def test_actual_404(self) -> None:
response = self.client.get("/does-not-exist/")
self.assertContains(
response, "<h1>There's nothing here!</h1>", html=True, status_code=404
)
def test_queries(self) -> None:
with self.assertNumQueries(20):
self.client.get(self.url)
class RobotsViewTestCase(SimpleTestCase):
url = reverse("robotstxt")
@override_settings(SEO_INDEX=True)
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["sitemap"], "http://testserver/sitemap.xml")
self.assertContains(response, "Allow: /")
self.assertTrue(response.context["SEO_INDEX"])
@override_settings(SEO_INDEX=False)
def test_disallow(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Disallow: /")
self.assertFalse(response.context["SEO_INDEX"])
class KeybaseViewTestCase(SimpleTestCase):
url = reverse("keybase")
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "I hereby claim")
class AllPagesFeedTestCase(TestCase):
url = reverse("feed")
def test_accessible(self) -> None:
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)