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.
 
 
 
 
 

46 lines
1.6 KiB

from hc.api.models import Channel, Check
from hc.test import BaseTestCase
class SwitchChannelTestCase(BaseTestCase):
def setUp(self):
super(SwitchChannelTestCase, self).setUp()
self.check = Check(user=self.alice)
self.check.save()
self.channel = Channel(user=self.alice, kind="email")
self.channel.value = "[email protected]"
self.channel.save()
self.url = "/checks/%s/channels/%s/enabled" % (self.check.code, self.channel.code)
def test_it_enables(self):
self.client.login(username="[email protected]", password="password")
self.client.post(self.url, {"state": "on"})
self.assertTrue(self.channel in self.check.channel_set.all())
def test_it_disables(self):
self.check.channel_set.add(self.channel)
self.client.login(username="[email protected]", password="password")
self.client.post(self.url, {"state": "off"})
self.assertFalse(self.channel in self.check.channel_set.all())
def test_it_checks_ownership(self):
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, {"state": "on"})
self.assertEqual(r.status_code, 403)
def test_it_checks_channels_ownership(self):
cc = Check(user=self.charlie)
cc.save()
# Charlie will try to assign Alice's channel to his check:
self.url = "/checks/%s/channels/%s/enabled" % (cc.code, self.channel.code)
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, {"state": "on"})
self.assertEqual(r.status_code, 403)