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.

85 lines
3.1 KiB

6 years ago
6 years ago
9 years ago
9 years ago
9 years ago
  1. from hc.accounts.models import Project
  2. from hc.api.models import Channel, Check
  3. from hc.test import BaseTestCase
  4. class UpdateChannelTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(UpdateChannelTestCase, self).setUp()
  7. self.check = Check.objects.create(project=self.project)
  8. self.channel = Channel(project=self.project, 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_project = Project.objects.create(owner=self.charlie)
  41. charlies_channel = Channel(project=charlies_project, kind="email")
  42. charlies_channel.email = "[email protected]"
  43. charlies_channel.save()
  44. payload = {
  45. "channel": charlies_channel.code,
  46. "check-%s" % self.check.code: True
  47. }
  48. self.client.login(username="[email protected]", password="password")
  49. r = self.client.post("/integrations/", data=payload)
  50. # mc belongs to charlie but self.check does not--
  51. assert r.status_code == 403
  52. def test_it_handles_missing_channel(self):
  53. # Correct UUID but there is no channel for it:
  54. payload = {"channel": "6837d6ec-fc08-4da5-a67f-08a9ed1ccf62"}
  55. self.client.login(username="[email protected]", password="password")
  56. r = self.client.post("/integrations/", data=payload)
  57. assert r.status_code == 400
  58. def test_it_handles_missing_check(self):
  59. # check- key has a correct UUID but there's no check object for it
  60. payload = {
  61. "channel": self.channel.code,
  62. "check-6837d6ec-fc08-4da5-a67f-08a9ed1ccf62": True
  63. }
  64. self.client.login(username="[email protected]", password="password")
  65. r = self.client.post("/integrations/", data=payload)
  66. assert r.status_code == 400