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.

63 lines
2.3 KiB

  1. from django.test.utils import override_settings
  2. from hc.api.models import Channel
  3. from hc.test import BaseTestCase
  4. @override_settings(SHELL_ENABLED=True)
  5. class AddShellTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(AddShellTestCase, self).setUp()
  8. self.url = "/projects/%s/add_shell/" % self.project.code
  9. @override_settings(SHELL_ENABLED=False)
  10. def test_it_is_disabled_by_default(self):
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.get(self.url)
  13. self.assertEqual(r.status_code, 404)
  14. def test_instructions_work(self):
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get(self.url)
  17. self.assertContains(r, "Executes a local shell command")
  18. def test_it_adds_two_commands_and_redirects(self):
  19. form = {"cmd_down": "logger down", "cmd_up": "logger up"}
  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.project, self.project)
  25. self.assertEqual(c.cmd_down, "logger down")
  26. self.assertEqual(c.cmd_up, "logger up")
  27. def test_it_adds_webhook_using_team_access(self):
  28. form = {"cmd_down": "logger down", "cmd_up": "logger up"}
  29. # Logging in as bob, not alice. Bob has team access so this
  30. # should work.
  31. self.client.login(username="[email protected]", password="password")
  32. self.client.post(self.url, form)
  33. c = Channel.objects.get()
  34. self.assertEqual(c.project, self.project)
  35. self.assertEqual(c.cmd_down, "logger down")
  36. def test_it_handles_empty_down_command(self):
  37. form = {"cmd_down": "", "cmd_up": "logger up"}
  38. self.client.login(username="[email protected]", password="password")
  39. self.client.post(self.url, form)
  40. c = Channel.objects.get()
  41. self.assertEqual(c.cmd_down, "")
  42. self.assertEqual(c.cmd_up, "logger up")
  43. def test_it_requires_rw_access(self):
  44. self.bobs_membership.rw = False
  45. self.bobs_membership.save()
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.get(self.url)
  48. self.assertEqual(r.status_code, 403)