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.

84 lines
3.0 KiB

9 years ago
9 years ago
9 years ago
  1. from hc.api.models import Channel, Check
  2. from hc.test import BaseTestCase
  3. class UpdateChannelTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(UpdateChannelTestCase, self).setUp()
  6. self.check = Check(user=self.alice)
  7. self.check.save()
  8. self.channel = Channel(user=self.alice, kind="email")
  9. self.channel.email = "[email protected]"
  10. self.channel.save()
  11. def test_it_works(self):
  12. payload = {
  13. "channel": self.channel.code,
  14. "check-%s" % self.check.code: True
  15. }
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.post("/integrations/", data=payload)
  18. self.assertRedirects(r, "/integrations/")
  19. channel = Channel.objects.get(code=self.channel.code)
  20. checks = channel.checks.all()
  21. assert len(checks) == 1
  22. assert checks[0].code == self.check.code
  23. def test_team_access_works(self):
  24. payload = {
  25. "channel": self.channel.code,
  26. "check-%s" % self.check.code: True
  27. }
  28. # Logging in as bob, not alice. Bob has team access so this
  29. # should work.
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post("/integrations/", data=payload, follow=True)
  32. self.assertEqual(r.status_code, 200)
  33. def test_it_checks_channel_user(self):
  34. payload = {"channel": self.channel.code}
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.post("/integrations/", data=payload)
  37. # self.channel does not belong to charlie, this should fail--
  38. assert r.status_code == 403
  39. def test_it_checks_check_user(self):
  40. charlies_channel = Channel(user=self.charlie, kind="email")
  41. charlies_channel.email = "[email protected]"
  42. charlies_channel.save()
  43. payload = {
  44. "channel": charlies_channel.code,
  45. "check-%s" % self.check.code: True
  46. }
  47. self.client.login(username="[email protected]", password="password")
  48. r = self.client.post("/integrations/", data=payload)
  49. # mc belongs to charlie but self.check does not--
  50. assert r.status_code == 403
  51. def test_it_handles_missing_channel(self):
  52. # Correct UUID but there is no channel for it:
  53. payload = {"channel": "6837d6ec-fc08-4da5-a67f-08a9ed1ccf62"}
  54. self.client.login(username="[email protected]", password="password")
  55. r = self.client.post("/integrations/", data=payload)
  56. assert r.status_code == 400
  57. def test_it_handles_missing_check(self):
  58. # check- key has a correct UUID but there's no check object for it
  59. payload = {
  60. "channel": self.channel.code,
  61. "check-6837d6ec-fc08-4da5-a67f-08a9ed1ccf62": True
  62. }
  63. self.client.login(username="[email protected]", password="password")
  64. r = self.client.post("/integrations/", data=payload)
  65. assert r.status_code == 400