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.

50 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. def setUp(self):
  6. super(AddOpsGenieTestCase, self).setUp()
  7. self.url = "/projects/%s/add_opsgenie/" % 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, "escalation policies and incident tracking")
  12. def test_it_works(self):
  13. form = {"key": "123456", "region": "us"}
  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, "opsgenie")
  19. payload = json.loads(c.value)
  20. self.assertEqual(payload["key"], "123456")
  21. self.assertEqual(payload["region"], "us")
  22. self.assertEqual(c.project, self.project)
  23. def test_it_trims_whitespace(self):
  24. form = {"key": " 123456 ", "region": "us"}
  25. self.client.login(username="[email protected]", password="password")
  26. self.client.post(self.url, form)
  27. c = Channel.objects.get()
  28. payload = json.loads(c.value)
  29. self.assertEqual(payload["key"], "123456")
  30. def test_it_saves_eu_region(self):
  31. form = {"key": "123456", "region": "eu"}
  32. self.client.login(username="[email protected]", password="password")
  33. self.client.post(self.url, form)
  34. c = Channel.objects.get()
  35. payload = json.loads(c.value)
  36. self.assertEqual(payload["region"], "eu")