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.

39 lines
1.5 KiB

  1. from unittest.mock import patch
  2. from django.test.utils import override_settings
  3. from hc.api.models import Channel
  4. from hc.test import BaseTestCase
  5. @override_settings(MATRIX_ACCESS_TOKEN="foo")
  6. @override_settings(MATRIX_HOMESERVER="fake-homeserver")
  7. class AddMatrixTestCase(BaseTestCase):
  8. def setUp(self):
  9. super(AddMatrixTestCase, self).setUp()
  10. self.url = "/projects/%s/add_matrix/" % self.project.code
  11. @override_settings(MATRIX_ACCESS_TOKEN="foo")
  12. def test_instructions_work(self):
  13. self.client.login(username="[email protected]", password="password")
  14. r = self.client.get(self.url)
  15. self.assertContains(r, "Integration Settings", status_code=200)
  16. @patch("hc.front.forms.requests.post")
  17. def test_it_works(self, mock_post):
  18. mock_post.return_value.json.return_value = {"room_id": "fake-room-id"}
  19. form = {"alias": "!foo:example.org"}
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.post(self.url, form)
  22. self.assertRedirects(r, self.channels_url)
  23. c = Channel.objects.get()
  24. self.assertEqual(c.kind, "matrix")
  25. self.assertEqual(c.value, "fake-room-id")
  26. self.assertEqual(c.project, self.project)
  27. @override_settings(MATRIX_ACCESS_TOKEN=None)
  28. def test_it_requires_access_token(self):
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 404)