test_templates.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import pytest
  2. from django.contrib.auth import get_user_model
  3. from django.test import override_settings, TestCase
  4. EXPECTED_BANNER_HTML = """
  5. <div class="codered-banner" style="background-color:#f00; color:#fff; width:100%; padding:4px;">
  6. Test
  7. </div>
  8. """
  9. @pytest.mark.django_db
  10. class TestSiteBanner(TestCase):
  11. @override_settings(CRX_BANNER="Test")
  12. def test_with_banner(self):
  13. response = self.client.get("/")
  14. self.assertEqual(response.status_code, 200)
  15. self.assertInHTML(EXPECTED_BANNER_HTML, response.content.decode("utf-8"))
  16. def test_without_banner(self):
  17. response = self.client.get("/")
  18. self.assertEqual(response.status_code, 200)
  19. self.assertNotIn("codered-banner", response.content.decode("utf-8"))
  20. @pytest.mark.django_db
  21. class TestWagtailAdminBanner(TestCase):
  22. def setUp(self):
  23. admin = get_user_model().objects.create_superuser(
  24. "admin",
  25. email="admin@example.com",
  26. password="admin"
  27. )
  28. self.client.force_login(admin)
  29. def tearDown(self):
  30. self.client.logout()
  31. @override_settings(CRX_BANNER="Test")
  32. def test_with_banner(self):
  33. response = self.client.get("/admin/")
  34. self.assertEqual(response.status_code, 200)
  35. self.assertInHTML(EXPECTED_BANNER_HTML, response.content.decode("utf-8"))
  36. def test_without_banner(self):
  37. response = self.client.get("/admin/")
  38. self.assertEqual(response.status_code, 200)
  39. self.assertNotIn("codered-banner", response.content.decode("utf-8"))