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
1.9 KiB

  1. from hc.api.models import Channel, Check
  2. from hc.test import BaseTestCase
  3. class SwitchChannelTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(SwitchChannelTestCase, self).setUp()
  6. self.check = Check(user=self.alice)
  7. self.check.save()
  8. self.channel = Channel(user=self.alice, 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. cc = Check(user=self.charlie)
  27. cc.save()
  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_team = 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)