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.

47 lines
1.5 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 RemoveCheckTestCase(BaseTestCase):
  5. def setUp(self):
  6. super(RemoveCheckTestCase, self).setUp()
  7. self.check = Check(user=self.alice)
  8. self.check.save()
  9. def test_it_works(self):
  10. url = "/checks/%s/remove/" % self.check.code
  11. self.client.login(username="[email protected]", password="password")
  12. r = self.client.post(url)
  13. self.assertRedirects(r, "/checks/")
  14. assert Check.objects.count() == 0
  15. def test_it_handles_bad_uuid(self):
  16. url = "/checks/not-uuid/remove/"
  17. self.client.login(username="[email protected]", password="password")
  18. r = self.client.post(url)
  19. assert r.status_code == 400
  20. def test_it_checks_owner(self):
  21. url = "/checks/%s/remove/" % self.check.code
  22. mallory = User(username="mallory", email="[email protected]")
  23. mallory.set_password("password")
  24. mallory.save()
  25. self.client.login(username="[email protected]", password="password")
  26. r = self.client.post(url)
  27. assert r.status_code == 403
  28. def test_it_handles_missing_uuid(self):
  29. # Valid UUID but there is no check for it:
  30. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.post(url)
  33. assert r.status_code == 404