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.

54 lines
1.8 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. check = Check.objects.get()
  12. self.assertEqual(check.project, self.project)
  13. redirect_url = "/checks/%s/details/?new" % check.code
  14. self.assertRedirects(r, redirect_url)
  15. def test_it_handles_unset_current_project(self):
  16. self.profile.current_project = None
  17. self.profile.save()
  18. self.client.login(username="[email protected]", password="password")
  19. r = self.client.post(self.url)
  20. check = Check.objects.get()
  21. self.assertEqual(check.project, self.project)
  22. redirect_url = "/checks/%s/details/?new" % check.code
  23. self.assertRedirects(r, redirect_url)
  24. def test_team_access_works(self):
  25. self.client.login(username="[email protected]", password="password")
  26. self.client.post(self.url)
  27. check = Check.objects.get()
  28. # Added by bob, but should belong to alice (bob has team access)
  29. self.assertEqual(check.project, self.project)
  30. def test_it_rejects_get(self):
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get(self.url)
  33. self.assertEqual(r.status_code, 405)
  34. def test_it_obeys_check_limit(self):
  35. self.profile.check_limit = 0
  36. self.profile.save()
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.post(self.url)
  39. self.assertEqual(r.status_code, 400)