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

9 years ago
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 RemoveCheckTestCase(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/remove/" % self.check.code
  13. self.client.login(username="alice", password="password")
  14. r = self.client.post(url)
  15. assert r.status_code == 302
  16. assert Check.objects.count() == 0
  17. def test_it_handles_bad_uuid(self):
  18. url = "/checks/not-uuid/remove/"
  19. self.client.login(username="alice", password="password")
  20. r = self.client.post(url)
  21. assert r.status_code == 400
  22. def test_it_checks_owner(self):
  23. url = "/checks/%s/remove/" % self.check.code
  24. mallory = User(username="mallory")
  25. mallory.set_password("password")
  26. mallory.save()
  27. self.client.login(username="mallory", password="password")
  28. r = self.client.post(url)
  29. assert r.status_code == 403
  30. def test_it_handles_missing_uuid(self):
  31. # Valid UUID but there is no check for it:
  32. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
  33. self.client.login(username="alice", password="password")
  34. r = self.client.post(url)
  35. assert r.status_code == 404