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.

88 lines
2.9 KiB

  1. from hc.api.models import Channel
  2. from hc.test import BaseTestCase
  3. class AddZulipTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(AddZulipTestCase, self).setUp()
  6. self.url = "/projects/%s/add_zulip/" % self.project.code
  7. def test_instructions_work(self):
  8. self.client.login(username="[email protected]", password="password")
  9. r = self.client.get(self.url)
  10. self.assertContains(r, "open-source group chat app")
  11. def test_it_works(self):
  12. form = {
  13. "bot_email": "[email protected]",
  14. "api_key": "fake-key",
  15. "mtype": "stream",
  16. "to": "general",
  17. }
  18. self.client.login(username="[email protected]", password="password")
  19. r = self.client.post(self.url, form)
  20. self.assertRedirects(r, self.channels_url)
  21. c = Channel.objects.get()
  22. self.assertEqual(c.kind, "zulip")
  23. self.assertEqual(c.zulip_bot_email, "[email protected]")
  24. self.assertEqual(c.zulip_api_key, "fake-key")
  25. self.assertEqual(c.zulip_type, "stream")
  26. self.assertEqual(c.zulip_to, "general")
  27. def test_it_rejects_bad_email(self):
  28. form = {
  29. "bot_email": "not@an@email",
  30. "api_key": "fake-key",
  31. "mtype": "stream",
  32. "to": "general",
  33. }
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.post(self.url, form)
  36. self.assertContains(r, "Enter a valid email address.")
  37. def test_it_rejects_missing_api_key(self):
  38. form = {
  39. "bot_email": "[email protected]",
  40. "api_key": "",
  41. "mtype": "stream",
  42. "to": "general",
  43. }
  44. self.client.login(username="[email protected]", password="password")
  45. r = self.client.post(self.url, form)
  46. self.assertContains(r, "This field is required.")
  47. def test_it_rejects_bad_mtype(self):
  48. form = {
  49. "bot_email": "[email protected]",
  50. "api_key": "fake-key",
  51. "mtype": "this-should-not-work",
  52. "to": "general",
  53. }
  54. self.client.login(username="[email protected]", password="password")
  55. r = self.client.post(self.url, form)
  56. self.assertEqual(r.status_code, 200)
  57. def test_it_rejects_missing_stream_name(self):
  58. form = {
  59. "bot_email": "[email protected]",
  60. "api_key": "fake-key",
  61. "mtype": "stream",
  62. "to": "",
  63. }
  64. self.client.login(username="[email protected]", password="password")
  65. r = self.client.post(self.url, form)
  66. self.assertContains(r, "This field is required.")
  67. def test_it_requires_rw_access(self):
  68. self.bobs_membership.rw = False
  69. self.bobs_membership.save()
  70. self.client.login(username="[email protected]", password="password")
  71. r = self.client.get(self.url)
  72. self.assertEqual(r.status_code, 403)