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.

48 lines
1.7 KiB

  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class AddCheckTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(AddCheckTestCase, self).setUp()
  6. self.url = "/projects/%s/checks/add/" % self.project.code
  7. self.redirect_url = "/projects/%s/checks/" % self.project.code
  8. def test_it_works(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.post(self.url)
  11. self.assertRedirects(r, self.redirect_url)
  12. check = Check.objects.get()
  13. self.assertEqual(check.project, self.project)
  14. def test_it_handles_unset_current_project(self):
  15. self.profile.current_project = None
  16. self.profile.save()
  17. self.client.login(username="[email protected]", password="password")
  18. r = self.client.post(self.url)
  19. self.assertRedirects(r, self.redirect_url)
  20. check = Check.objects.get()
  21. self.assertEqual(check.project, self.project)
  22. def test_team_access_works(self):
  23. self.client.login(username="[email protected]", password="password")
  24. self.client.post(self.url)
  25. check = Check.objects.get()
  26. # Added by bob, but should belong to alice (bob has team access)
  27. self.assertEqual(check.project, self.project)
  28. def test_it_rejects_get(self):
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertEqual(r.status_code, 405)
  32. def test_it_obeys_check_limit(self):
  33. self.profile.check_limit = 0
  34. self.profile.save()
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.post(self.url)
  37. self.assertEqual(r.status_code, 400)