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.
 
 
 
 
 

80 lines
2.6 KiB

from hc.api.models import Channel
from hc.test import BaseTestCase
class AddZulipTestCase(BaseTestCase):
def setUp(self):
super(AddZulipTestCase, self).setUp()
self.url = "/projects/%s/add_zulip/" % self.project.code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertContains(r, "open-source group chat app")
def test_it_works(self):
form = {
"bot_email": "[email protected]",
"api_key": "fake-key",
"mtype": "stream",
"to": "general",
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, self.channels_url)
c = Channel.objects.get()
self.assertEqual(c.kind, "zulip")
self.assertEqual(c.zulip_bot_email, "[email protected]")
self.assertEqual(c.zulip_api_key, "fake-key")
self.assertEqual(c.zulip_type, "stream")
self.assertEqual(c.zulip_to, "general")
def test_it_rejects_bad_email(self):
form = {
"bot_email": "not@an@email",
"api_key": "fake-key",
"mtype": "stream",
"to": "general",
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertContains(r, "Enter a valid email address.")
def test_it_rejects_missing_api_key(self):
form = {
"bot_email": "[email protected]",
"api_key": "",
"mtype": "stream",
"to": "general",
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertContains(r, "This field is required.")
def test_it_rejects_bad_mtype(self):
form = {
"bot_email": "[email protected]",
"api_key": "fake-key",
"mtype": "this-should-not-work",
"to": "general",
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertEqual(r.status_code, 200)
def test_it_rejects_missing_stream_name(self):
form = {
"bot_email": "[email protected]",
"api_key": "fake-key",
"mtype": "stream",
"to": "",
}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertContains(r, "This field is required.")