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.

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