test_status_page.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.urls import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import GlitchTipTestCase
  4. class StatusPageTestCase(GlitchTipTestCase):
  5. def setUp(self):
  6. self.create_user_and_project()
  7. def test_status_page(self):
  8. status_page = baker.make(
  9. "uptime.StatusPage", organization=self.organization, is_public=False
  10. )
  11. url = status_page.get_absolute_url()
  12. res = self.client.get(url)
  13. self.assertContains(res, status_page.name)
  14. self.client.logout()
  15. res = self.client.get(url)
  16. self.assertEqual(res.status_code, 404)
  17. status_page.is_public = True
  18. status_page.save()
  19. res = self.client.get(url)
  20. self.assertContains(res, status_page.name)
  21. def test_status_page_api(self):
  22. status_page = baker.make("uptime.StatusPage", organization=self.organization)
  23. other_status_page = baker.make("uptime.StatusPage")
  24. url = reverse("organization-status-pages-list", args=(self.organization.slug,))
  25. res = self.client.get(url)
  26. self.assertContains(res, status_page.name)
  27. self.assertNotContains(res, other_status_page.name)
  28. def test_status_page_api_create(self):
  29. url = reverse("organization-status-pages-list", args=(self.organization.slug,))
  30. data = {"name": "foo"}
  31. res = self.client.post(url, data)
  32. self.assertContains(res, data["name"], status_code=201)