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.

56 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.objects.create(project=self.project)
  7. self.remove_url = "/checks/%s/remove/" % self.check.code
  8. def test_it_works(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.post(self.remove_url)
  11. self.assertRedirects(r, "/checks/")
  12. self.assertEqual(Check.objects.count(), 0)
  13. def test_team_access_works(self):
  14. # Logging in as bob, not alice. Bob has team access so this
  15. # should work.
  16. self.client.login(username="[email protected]", password="password")
  17. self.client.post(self.remove_url)
  18. self.assertEqual(Check.objects.count(), 0)
  19. def test_it_handles_bad_uuid(self):
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.post("/checks/not-uuid/remove/")
  22. self.assertEqual(r.status_code, 404)
  23. def test_it_checks_owner(self):
  24. self.client.login(username="[email protected]", password="password")
  25. r = self.client.post(self.remove_url)
  26. self.assertEqual(r.status_code, 404)
  27. def test_it_handles_missing_uuid(self):
  28. # Valid UUID but there is no check for it:
  29. url = "/checks/6837d6ec-fc08-4da5-a67f-08a9ed1ccf62/remove/"
  30. self.client.login(username="[email protected]", password="password")
  31. r = self.client.post(url)
  32. self.assertEqual(r.status_code, 404)
  33. def test_it_rejects_get(self):
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(self.remove_url)
  36. self.assertEqual(r.status_code, 405)
  37. def test_it_allows_cross_team_access(self):
  38. self.bobs_profile.current_project = None
  39. self.bobs_profile.save()
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.post(self.remove_url)
  42. self.assertRedirects(r, "/checks/")