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 datetime import timedelta as td
  2. import uuid
  3. from django.utils.timezone import now
  4. from hc.api.models import Channel, Check
  5. from hc.test import BaseTestCase
  6. class GetCheckTestCase(BaseTestCase):
  7. def setUp(self):
  8. super(GetCheckTestCase, self).setUp()
  9. self.now = now().replace(microsecond=0)
  10. self.a1 = Check(project=self.project, name="Alice 1")
  11. self.a1.timeout = td(seconds=3600)
  12. self.a1.grace = td(seconds=900)
  13. self.a1.n_pings = 0
  14. self.a1.status = "new"
  15. self.a1.tags = "a1-tag a1-additional-tag"
  16. self.a1.desc = "This is description"
  17. self.a1.save()
  18. self.c1 = Channel.objects.create(project=self.project)
  19. self.a1.channel_set.add(self.c1)
  20. def get(self, code):
  21. url = "/api/v1/checks/%s" % code
  22. return self.client.get(url, HTTP_X_API_KEY="X" * 32)
  23. def test_it_works(self):
  24. r = self.get(self.a1.code)
  25. self.assertEqual(r.status_code, 200)
  26. self.assertEqual(r["Access-Control-Allow-Origin"], "*")
  27. doc = r.json()
  28. self.assertEqual(len(doc), 13)
  29. self.assertEqual(doc["timeout"], 3600)
  30. self.assertEqual(doc["grace"], 900)
  31. self.assertEqual(doc["ping_url"], self.a1.url())
  32. self.assertEqual(doc["last_ping"], None)
  33. self.assertEqual(doc["n_pings"], 0)
  34. self.assertEqual(doc["status"], "new")
  35. self.assertEqual(doc["channels"], str(self.c1.code))
  36. self.assertEqual(doc["desc"], "This is description")
  37. def test_it_handles_invalid_uuid(self):
  38. r = self.get("not-an-uuid")
  39. self.assertEqual(r.status_code, 404)
  40. def test_it_handles_missing_check(self):
  41. made_up_code = "07c2f548-9850-4b27-af5d-6c9dc157ec02"
  42. r = self.get(made_up_code)
  43. self.assertEqual(r.status_code, 404)