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.

57 lines
2.0 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. @override_settings(PD_APP_ID=None)
  5. class AddPdTestCase(BaseTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. self.url = "/projects/%s/add_pd/" % self.project.code
  9. def test_instructions_work(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "Paste the Integration Key down below")
  13. def test_it_works(self):
  14. # Integration key is 32 characters long
  15. form = {"value": "12345678901234567890123456789012"}
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.post(self.url, form)
  18. self.assertRedirects(r, self.channels_url)
  19. c = Channel.objects.get()
  20. self.assertEqual(c.kind, "pd")
  21. self.assertEqual(c.value, "12345678901234567890123456789012")
  22. def test_it_trims_whitespace(self):
  23. form = {"value": " 123456 "}
  24. self.client.login(username="[email protected]", password="password")
  25. self.client.post(self.url, form)
  26. c = Channel.objects.get()
  27. self.assertEqual(c.value, "123456")
  28. def test_it_requires_rw_access(self):
  29. self.bobs_membership.rw = False
  30. self.bobs_membership.save()
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get(self.url)
  33. self.assertEqual(r.status_code, 403)
  34. @override_settings(PD_ENABLED=False)
  35. def test_it_handles_disabled_integration(self):
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.get(self.url)
  38. self.assertEqual(r.status_code, 404)
  39. @override_settings(PD_APP_ID="FOOBAR")
  40. def test_it_handles_pd_app_id(self):
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get(self.url)
  43. self.assertContains(r, "app_id=FOOBAR")
  44. self.assertIn("pagerduty", self.client.session)