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.

47 lines
1.7 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. class AddVictorOpsTestCase(BaseTestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.url = "/projects/%s/add_victorops/" % self.project.code
  8. def test_instructions_work(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get(self.url)
  11. self.assertContains(r, "incident management platform")
  12. def test_it_works(self):
  13. form = {"value": "http://example.org"}
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.post(self.url, form)
  16. self.assertRedirects(r, self.channels_url)
  17. c = Channel.objects.get()
  18. self.assertEqual(c.kind, "victorops")
  19. self.assertEqual(c.value, "http://example.org")
  20. self.assertEqual(c.project, self.project)
  21. def test_it_rejects_bad_url(self):
  22. form = {"value": "not an URL"}
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.post(self.url, form)
  25. self.assertContains(r, "Enter a valid URL")
  26. def test_it_requires_rw_access(self):
  27. self.bobs_membership.role = "r"
  28. self.bobs_membership.save()
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 403)
  32. @override_settings(VICTOROPS_ENABLED=False)
  33. def test_it_handles_disabled_integration(self):
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(self.url)
  36. self.assertEqual(r.status_code, 404)