2
0

test_wagtailsettings_models.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from django.test import Client
  2. from wagtail.test.utils import WagtailPageTests
  3. from wagtail.models import Site
  4. from wagtailcrx.tests.testapp.models import WebPage
  5. from wagtailcrx.models.wagtailsettings_models import AnalyticsSettings
  6. class AnalyticsSettingsTestCase(WagtailPageTests):
  7. """
  8. Test that the relevant analytics settings appear in the homepage HTML.
  9. """
  10. model = WebPage
  11. def setUp(self):
  12. # HTTP client.
  13. self.client = Client()
  14. # Use home page and default site.
  15. self.site = Site.objects.filter(is_default_site=True)[0]
  16. self.homepage = WebPage.objects.get(url_path="/home/")
  17. # Populate settings.
  18. self.settings = AnalyticsSettings.for_site(self.site)
  19. self.settings.ga_tracking_id = "UA-123"
  20. self.settings.head_scripts = "<script>evil_tracker</script>"
  21. self.settings.body_scripts = "<script>annoying_tracker</script>"
  22. self.settings.save()
  23. def test_get(self):
  24. """
  25. Tests to make sure the page serves a 200 from a GET request.
  26. """
  27. response = self.client.get(self.homepage.url, follow=True)
  28. self.assertEqual(response.status_code, 200)
  29. def test_ga_tracking_id(self):
  30. """
  31. Make sure the ga_tracking_id is present.
  32. """
  33. response = self.client.get(self.homepage.url, follow=True)
  34. self.assertIn(self.settings.ga_tracking_id, str(response.content), 1)
  35. def test_head_scripts(self):
  36. """
  37. Make sure the head_scripts is present.
  38. """
  39. response = self.client.get(self.homepage.url, follow=True)
  40. self.assertInHTML(self.settings.head_scripts, str(response.content), 1)
  41. def test_body_scripts(self):
  42. """
  43. Make sure the body_scripts is present.
  44. """
  45. response = self.client.get(self.homepage.url, follow=True)
  46. self.assertInHTML(self.settings.body_scripts, str(response.content), 1)