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.

32 lines
1.2 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. from mock import patch
  5. class AddMatrixTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(AddMatrixTestCase, self).setUp()
  8. self.url = "/projects/%s/add_matrix/" % self.project.code
  9. @override_settings(MATRIX_ACCESS_TOKEN="foo")
  10. def test_instructions_work(self):
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.get(self.url)
  13. self.assertContains(r, "Integration Settings", status_code=200)
  14. @override_settings(MATRIX_ACCESS_TOKEN="foo")
  15. @override_settings(MATRIX_HOMESERVER="fake-homeserver")
  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)