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.

64 lines
2.4 KiB

6 years ago
  1. from hc.api.models import Check, Ping
  2. from hc.test import BaseTestCase
  3. class StatusSingleTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(StatusSingleTestCase, self).setUp()
  6. self.check = Check(project=self.project, name="Alice Was Here")
  7. self.check.save()
  8. def test_it_works(self):
  9. self.client.login(username="[email protected]", password="password")
  10. r = self.client.get("/checks/%s/status/" % self.check.code)
  11. doc = r.json()
  12. self.assertEqual(doc["status"], "new")
  13. self.assertTrue("never received a ping" in doc["status_text"])
  14. self.assertTrue("not received any pings yet" in doc["events"])
  15. def test_it_returns_events(self):
  16. p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1)
  17. self.check.status = "up"
  18. self.check.last_ping = p.created
  19. self.check.save()
  20. self.client.login(username="[email protected]", password="password")
  21. r = self.client.get("/checks/%s/status/" % self.check.code)
  22. doc = r.json()
  23. self.assertEqual(doc["status"], "up")
  24. self.assertEqual(doc["updated"], str(p.created.timestamp()))
  25. self.assertTrue("test-user-agent" in doc["events"])
  26. def test_it_omits_events(self):
  27. p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1)
  28. self.check.status = "up"
  29. self.check.last_ping = p.created
  30. self.check.save()
  31. timestamp = str(p.created.timestamp())
  32. url = "/checks/%s/status/?u=%s" % (self.check.code, timestamp)
  33. self.client.login(username="[email protected]", password="password")
  34. r = self.client.get(url)
  35. doc = r.json()
  36. self.assertFalse("events" in doc)
  37. def test_it_allows_cross_team_access(self):
  38. self.client.login(username="[email protected]", password="password")
  39. r = self.client.get("/checks/%s/status/" % self.check.code)
  40. self.assertEqual(r.status_code, 200)
  41. def test_it_handles_manual_resume(self):
  42. self.check.status = "paused"
  43. self.check.manual_resume = True
  44. self.check.save()
  45. self.client.login(username="[email protected]", password="password")
  46. r = self.client.get("/checks/%s/status/" % self.check.code)
  47. doc = r.json()
  48. self.assertEqual(doc["status"], "paused")
  49. self.assertTrue("will ignore pings until resumed" in doc["status_text"])