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.

58 lines
2.1 KiB

9 years ago
9 years ago
9 years ago
  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class RemoveCheckTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(RemoveCheckTestCase, self).setUp()
  6. self.check = Check(user=self.alice)
  7. self.check.save()
  8. self.remove_url = "/checks/%s/remove/" % self.check.code
  9. def test_it_works(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.post(self.remove_url)
  12. self.assertRedirects(r, "/checks/")
  13. self.assertEqual(Check.objects.count(), 0)
  14. def test_team_access_works(self):
  15. # Logging in as bob, not alice. Bob has team access so this
  16. # should work.
  17. self.client.login(username="[email protected]", password="password")
  18. self.client.post(self.remove_url)
  19. self.assertEqual(Check.objects.count(), 0)
  20. def test_it_handles_bad_uuid(self):
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.post("/checks/not-uuid/remove/")
  23. self.assertEqual(r.status_code, 404)
  24. def test_it_checks_owner(self):
  25. self.client.login(username="[email protected]", password="password")
  26. r = self.client.post(self.remove_url)
  27. self.assertEqual(r.status_code, 404)
  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. self.assertEqual(r.status_code, 404)
  34. def test_it_rejects_get(self):
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get(self.remove_url)
  37. self.assertEqual(r.status_code, 405)
  38. def test_it_allows_cross_team_access(self):
  39. self.bobs_profile.current_team = None
  40. self.bobs_profile.save()
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.post(self.remove_url)
  43. self.assertRedirects(r, "/checks/")