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.

49 lines
1.5 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, Ping
  4. class LogTestCase(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. ping = Ping(owner=self.check)
  12. ping.save()
  13. def test_it_works(self):
  14. url = "/checks/%s/log/" % self.check.code
  15. self.client.login(username="alice", password="password")
  16. r = self.client.get(url)
  17. self.assertContains(r, "Dates and times are", status_code=200)
  18. def test_it_handles_bad_uuid(self):
  19. url = "/checks/not-uuid/log/"
  20. self.client.login(username="alice", password="password")
  21. r = self.client.get(url)
  22. assert r.status_code == 400
  23. def test_it_handles_missing_uuid(self):
  24. # Valid UUID but there is no check for it:
  25. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/log/"
  26. self.client.login(username="alice", password="password")
  27. r = self.client.get(url)
  28. assert r.status_code == 404
  29. def test_it_checks_ownership(self):
  30. charlie = User(username="charlie")
  31. charlie.set_password("password")
  32. charlie.save()
  33. url = "/checks/%s/log/" % self.check.code
  34. self.client.login(username="charlie", password="password")
  35. r = self.client.get(url)
  36. assert r.status_code == 403