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.

55 lines
1.9 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.slug = "foo"
  9. self.check.subject = "success-keyword"
  10. self.check.subject_fail = "failure-keyword"
  11. self.check.methods = "POST"
  12. self.check.manual_resume = True
  13. self.check.save()
  14. self.copy_url = "/checks/%s/copy/" % self.check.code
  15. def test_it_works(self):
  16. self.client.login(username="[email protected]", password="password")
  17. r = self.client.post(self.copy_url, follow=True)
  18. self.assertContains(r, "This is a brand new check")
  19. copy = Check.objects.get(name="Foo (copy)")
  20. self.assertEqual(copy.slug, "foo-copy")
  21. self.assertEqual(copy.subject, "success-keyword")
  22. self.assertEqual(copy.subject_fail, "failure-keyword")
  23. self.assertEqual(copy.methods, "POST")
  24. self.assertTrue(copy.manual_resume)
  25. def test_it_obeys_limit(self):
  26. self.profile.check_limit = 0
  27. self.profile.save()
  28. self.client.login(username="[email protected]", password="password")
  29. r = self.client.post(self.copy_url)
  30. self.assertEqual(r.status_code, 400)
  31. def test_it_requires_rw_access(self):
  32. self.bobs_membership.role = "r"
  33. self.bobs_membership.save()
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.post(self.copy_url)
  36. self.assertEqual(r.status_code, 403)
  37. def test_it_handles_long_check_name(self):
  38. self.check.name = "A" * 100
  39. self.check.save()
  40. self.client.login(username="[email protected]", password="password")
  41. self.client.post(self.copy_url)
  42. q = Check.objects.filter(name="A" * 90 + "... (copy)")
  43. self.assertTrue(q.exists())