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.

54 lines
2.0 KiB

6 years ago
6 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 SwitchChannelTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(SwitchChannelTestCase, self).setUp()
  7. self.check = Check.objects.create(project=self.project)
  8. self.channel = Channel(project=self.project, kind="email")
  9. self.channel.value = "[email protected]"
  10. self.channel.save()
  11. self.url = "/checks/%s/channels/%s/enabled" % (self.check.code, self.channel.code)
  12. def test_it_enables(self):
  13. self.client.login(username="[email protected]", password="password")
  14. self.client.post(self.url, {"state": "on"})
  15. self.assertTrue(self.channel in self.check.channel_set.all())
  16. def test_it_disables(self):
  17. self.check.channel_set.add(self.channel)
  18. self.client.login(username="[email protected]", password="password")
  19. self.client.post(self.url, {"state": "off"})
  20. self.assertFalse(self.channel in self.check.channel_set.all())
  21. def test_it_checks_ownership(self):
  22. self.client.login(username="[email protected]", password="password")
  23. r = self.client.post(self.url, {"state": "on"})
  24. self.assertEqual(r.status_code, 404)
  25. def test_it_checks_channels_ownership(self):
  26. charlies_project = Project.objects.create(owner=self.charlie)
  27. cc = Check.objects.create(project=charlies_project)
  28. # Charlie will try to assign Alice's channel to his check:
  29. self.url = "/checks/%s/channels/%s/enabled" % (cc.code, self.channel.code)
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post(self.url, {"state": "on"})
  32. self.assertEqual(r.status_code, 400)
  33. def test_it_allows_cross_team_access(self):
  34. self.bobs_profile.current_project = None
  35. self.bobs_profile.save()
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.post(self.url, {"state": "on"})
  38. self.assertEqual(r.status_code, 200)