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.

61 lines
2.3 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().setUp()
  6. self.check = Check.objects.create(project=self.project)
  7. self.remove_url = "/checks/%s/remove/" % self.check.code
  8. self.redirect_url = "/projects/%s/checks/" % self.project.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, self.redirect_url)
  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.client.login(username="[email protected]", password="password")
  40. r = self.client.post(self.remove_url)
  41. self.assertRedirects(r, self.redirect_url)
  42. def test_it_requires_rw_access(self):
  43. self.bobs_membership.role = "r"
  44. self.bobs_membership.save()
  45. self.client.login(username="[email protected]", password="password")
  46. r = self.client.post(self.remove_url)
  47. self.assertEqual(r.status_code, 403)