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.

55 lines
1.8 KiB

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