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.

42 lines
1.6 KiB

5 years ago
  1. from django.test.utils import override_settings
  2. from hc.test import BaseTestCase
  3. @override_settings(SLACK_CLIENT_ID="fake-client-id")
  4. class AddSlackBtnTestCase(BaseTestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.url = "/projects/%s/add_slack_btn/" % 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, "Setup Guide", status_code=200)
  12. def test_slack_button(self):
  13. self.client.login(username="[email protected]", password="password")
  14. r = self.client.get(self.url)
  15. self.assertContains(r, "slack.com/oauth/v2/authorize", status_code=200)
  16. # There should now be a key in session
  17. self.assertTrue("add_slack" in self.client.session)
  18. @override_settings(SLACK_CLIENT_ID=None)
  19. def test_it_requires_client_id(self):
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.get(self.url)
  22. self.assertEqual(r.status_code, 404)
  23. def test_it_requires_rw_access(self):
  24. self.bobs_membership.role = "r"
  25. self.bobs_membership.save()
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.get(self.url)
  28. self.assertEqual(r.status_code, 403)
  29. @override_settings(SLACK_ENABLED=False)
  30. def test_it_handles_disabled_integration(self):
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get(self.url)
  33. self.assertEqual(r.status_code, 404)