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.

56 lines
2.0 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.bobs_profile.current_project = None
  39. self.bobs_profile.save()
  40. self.client.login(username="[email protected]", password="password")
  41. r = self.client.get("/checks/%s/status/" % self.check.code)
  42. self.assertEqual(r.status_code, 200)