test_status_page.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.urls import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import GlitchTestCase
  4. class StatusPageTestCase(GlitchTestCase):
  5. @classmethod
  6. def setUpTestData(cls):
  7. cls.create_user()
  8. def setUp(self):
  9. self.client.force_login(self.user)
  10. def test_status_page(self):
  11. status_page = baker.make(
  12. "uptime.StatusPage", organization=self.organization, is_public=False
  13. )
  14. url = status_page.get_absolute_url()
  15. res = self.client.get(url)
  16. self.assertContains(res, status_page.name)
  17. self.client.logout()
  18. res = self.client.get(url)
  19. self.assertEqual(res.status_code, 404)
  20. status_page.is_public = True
  21. status_page.save()
  22. res = self.client.get(url)
  23. self.assertContains(res, status_page.name)
  24. def test_status_page_api(self):
  25. status_page = baker.make("uptime.StatusPage", organization=self.organization)
  26. other_status_page = baker.make("uptime.StatusPage")
  27. url = reverse("api:list_status_pages", args=(self.organization.slug,))
  28. res = self.client.get(url)
  29. self.assertContains(res, status_page.name)
  30. self.assertNotContains(res, other_status_page.name)
  31. def test_status_page_api_create(self):
  32. url = reverse("api:create_status_page", args=(self.organization.slug,))
  33. data = {"name": "foo"}
  34. res = self.client.post(url, data, content_type="application/json")
  35. self.assertContains(res, data["name"], status_code=201)