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.8 KiB

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