You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

  1. from unittest.mock import patch
  2. from django.test import TestCase
  3. class ServeDocTestCase(TestCase):
  4. def test_it_serves_introduction(self):
  5. r = self.client.get("/docs/")
  6. self.assertEqual(r.status_code, 200)
  7. self.assertContains(r, "<strong>keeps silent</strong>")
  8. def test_it_serves_subpage(self):
  9. r = self.client.get("/docs/reliability_tips/")
  10. self.assertEqual(r.status_code, 200)
  11. self.assertContains(r, "Pinging Reliability Tips")
  12. def test_it_handles_bad_url(self):
  13. r = self.client.get("/docs/does_not_exist/")
  14. self.assertEqual(r.status_code, 404)
  15. @patch("hc.front.views.os.path.exists")
  16. def test_it_rejects_bad_characters(self, mock_exists):
  17. r = self.client.get("/docs/NAUGHTY/")
  18. self.assertEqual(r.status_code, 404)
  19. # URL dispatcher's slug filter lets the uppercase letters through,
  20. # but the view should still reject them, before any filesystem
  21. # operations
  22. self.assertFalse(mock_exists.called)