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.

40 lines
1.4 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. class AddMattermostTestCase(BaseTestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.url = "/projects/%s/add_mattermost/" % self.project.code
  8. def test_instructions_work(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get(self.url)
  11. self.assertContains(r, "Integration Settings", status_code=200)
  12. def test_it_works(self):
  13. form = {"value": "http://example.org"}
  14. self.client.login(username="[email protected]", password="password")
  15. r = self.client.post(self.url, form)
  16. self.assertRedirects(r, self.channels_url)
  17. c = Channel.objects.get()
  18. self.assertEqual(c.kind, "mattermost")
  19. self.assertEqual(c.value, "http://example.org")
  20. self.assertEqual(c.project, self.project)
  21. def test_it_requires_rw_access(self):
  22. self.bobs_membership.rw = False
  23. self.bobs_membership.save()
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.get(self.url)
  26. self.assertEqual(r.status_code, 403)
  27. @override_settings(MATTERMOST_ENABLED=False)
  28. def test_it_handles_disabled_integration(self):
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 404)