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.

53 lines
1.8 KiB

  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class CopyCheckTestCase(BaseTestCase):
  4. def setUp(self):
  5. super().setUp()
  6. self.check = Check(project=self.project)
  7. self.check.name = "Foo"
  8. self.check.subject = "success-keyword"
  9. self.check.subject_fail = "failure-keyword"
  10. self.check.methods = "POST"
  11. self.check.manual_resume = True
  12. self.check.save()
  13. self.copy_url = "/checks/%s/copy/" % self.check.code
  14. def test_it_works(self):
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.post(self.copy_url, follow=True)
  17. self.assertContains(r, "This is a brand new check")
  18. copy = Check.objects.get(name="Foo (copy)")
  19. self.assertEqual(copy.subject, "success-keyword")
  20. self.assertEqual(copy.subject_fail, "failure-keyword")
  21. self.assertEqual(copy.methods, "POST")
  22. self.assertTrue(copy.manual_resume)
  23. def test_it_obeys_limit(self):
  24. self.profile.check_limit = 0
  25. self.profile.save()
  26. self.client.login(username="[email protected]", password="password")
  27. r = self.client.post(self.copy_url)
  28. self.assertEqual(r.status_code, 400)
  29. def test_it_requires_rw_access(self):
  30. self.bobs_membership.role = "r"
  31. self.bobs_membership.save()
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.post(self.copy_url)
  34. self.assertEqual(r.status_code, 403)
  35. def test_it_handles_long_check_name(self):
  36. self.check.name = "A" * 100
  37. self.check.save()
  38. self.client.login(username="[email protected]", password="password")
  39. self.client.post(self.copy_url)
  40. q = Check.objects.filter(name="A" * 90 + "... (copy)")
  41. self.assertTrue(q.exists())