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.

59 lines
2.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class UpdateTimeoutTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(UpdateTimeoutTestCase, self).setUp()
  6. self.check = Check(user=self.alice)
  7. self.check.save()
  8. def test_it_works(self):
  9. url = "/checks/%s/timeout/" % self.check.code
  10. payload = {"timeout": 3600, "grace": 60}
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.post(url, data=payload)
  13. self.assertRedirects(r, "/checks/")
  14. check = Check.objects.get(code=self.check.code)
  15. assert check.timeout.total_seconds() == 3600
  16. assert check.grace.total_seconds() == 60
  17. def test_team_access_works(self):
  18. url = "/checks/%s/timeout/" % self.check.code
  19. payload = {"timeout": 7200, "grace": 60}
  20. # Logging in as bob, not alice. Bob has team access so this
  21. # should work.
  22. self.client.login(username="[email protected]", password="password")
  23. self.client.post(url, data=payload)
  24. check = Check.objects.get(code=self.check.code)
  25. assert check.timeout.total_seconds() == 7200
  26. def test_it_handles_bad_uuid(self):
  27. url = "/checks/not-uuid/timeout/"
  28. payload = {"timeout": 3600, "grace": 60}
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.post(url, data=payload)
  31. assert r.status_code == 400
  32. def test_it_handles_missing_uuid(self):
  33. # Valid UUID but there is no check for it:
  34. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/timeout/"
  35. payload = {"timeout": 3600, "grace": 60}
  36. self.client.login(username="[email protected]", password="password")
  37. r = self.client.post(url, data=payload)
  38. assert r.status_code == 404
  39. def test_it_checks_ownership(self):
  40. url = "/checks/%s/timeout/" % self.check.code
  41. payload = {"timeout": 3600, "grace": 60}
  42. self.client.login(username="[email protected]", password="password")
  43. r = self.client.post(url, data=payload)
  44. assert r.status_code == 403