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.

43 lines
1.4 KiB

  1. from hc.api.models import Check
  2. from hc.test import BaseTestCase
  3. class MetricsTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(MetricsTestCase, self).setUp()
  6. self.project.api_key_readonly = "R" * 32
  7. self.project.save()
  8. self.check = Check(project=self.project, name="Alice Was Here")
  9. self.check.tags = "foo"
  10. self.check.save()
  11. key = "R" * 32
  12. self.url = "/projects/%s/checks/metrics/%s" % (self.project.code, key)
  13. def test_it_works(self):
  14. r = self.client.get(self.url)
  15. self.assertEqual(r.status_code, 200)
  16. self.assertContains(r, 'name="Alice Was Here"')
  17. self.assertContains(r, 'tags="foo"')
  18. self.assertContains(r, 'tag="foo"')
  19. self.assertContains(r, "hc_checks_total 1")
  20. def test_it_escapes_newline(self):
  21. self.check.name = "Line 1\nLine2"
  22. self.check.tags = "A\\C"
  23. self.check.save()
  24. r = self.client.get(self.url)
  25. self.assertEqual(r.status_code, 200)
  26. self.assertContains(r, "Line 1\\nLine2")
  27. self.assertContains(r, "A\\\\C")
  28. def test_it_checks_api_key_length(self):
  29. r = self.client.get(self.url + "R")
  30. self.assertEqual(r.status_code, 400)
  31. def test_it_checks_api_key(self):
  32. url = "/projects/%s/checks/metrics/%s" % (self.project.code, "X" * 32)
  33. r = self.client.get(url)
  34. self.assertEqual(r.status_code, 403)