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.

88 lines
3.2 KiB

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