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.

48 lines
1.6 KiB

8 years ago
  1. import json
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. class AddOpsGenieTestCase(BaseTestCase):
  5. url = "/integrations/add_opsgenie/"
  6. def test_instructions_work(self):
  7. self.client.login(username="[email protected]", password="password")
  8. r = self.client.get(self.url)
  9. self.assertContains(r, "escalation policies and incident tracking")
  10. def test_it_works(self):
  11. form = {"key": "123456", "region": "us"}
  12. self.client.login(username="[email protected]", password="password")
  13. r = self.client.post(self.url, form)
  14. self.assertRedirects(r, "/integrations/")
  15. c = Channel.objects.get()
  16. self.assertEqual(c.kind, "opsgenie")
  17. payload = json.loads(c.value)
  18. self.assertEqual(payload["key"], "123456")
  19. self.assertEqual(payload["region"], "us")
  20. self.assertEqual(c.project, self.project)
  21. def test_it_trims_whitespace(self):
  22. form = {"key": " 123456 ", "region": "us"}
  23. self.client.login(username="[email protected]", password="password")
  24. self.client.post(self.url, form)
  25. c = Channel.objects.get()
  26. payload = json.loads(c.value)
  27. self.assertEqual(payload["key"], "123456")
  28. def test_it_saves_eu_region(self):
  29. form = {"key": "123456", "region": "eu"}
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post(self.url, form)
  32. c = Channel.objects.get()
  33. payload = json.loads(c.value)
  34. self.assertEqual(payload["region"], "eu")