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.

53 lines
1.9 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. url = "/integrations/add_shell/"
  7. @override_settings(SHELL_ENABLED=False)
  8. def test_it_is_disabled_by_default(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get(self.url)
  11. self.assertEqual(r.status_code, 404)
  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, "Executes a local shell command")
  16. def test_it_adds_two_commands_and_redirects(self):
  17. form = {"cmd_down": "logger down", "cmd_up": "logger up"}
  18. self.client.login(username="[email protected]", password="password")
  19. r = self.client.post(self.url, form)
  20. self.assertRedirects(r, "/integrations/")
  21. c = Channel.objects.get()
  22. self.assertEqual(c.project, self.project)
  23. self.assertEqual(c.cmd_down, "logger down")
  24. self.assertEqual(c.cmd_up, "logger up")
  25. def test_it_adds_webhook_using_team_access(self):
  26. form = {"cmd_down": "logger down", "cmd_up": "logger up"}
  27. # Logging in as bob, not alice. Bob has team access so this
  28. # should work.
  29. self.client.login(username="[email protected]", password="password")
  30. self.client.post(self.url, form)
  31. c = Channel.objects.get()
  32. self.assertEqual(c.project, self.project)
  33. self.assertEqual(c.cmd_down, "logger down")
  34. def test_it_handles_empty_down_command(self):
  35. form = {"cmd_down": "", "cmd_up": "logger up"}
  36. self.client.login(username="[email protected]", password="password")
  37. self.client.post(self.url, form)
  38. c = Channel.objects.get()
  39. self.assertEqual(c.cmd_down, "")
  40. self.assertEqual(c.cmd_up, "logger up")