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.

57 lines
2.1 KiB

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