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.

57 lines
2.1 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(user=self.alice, name="Alice Was Here")
  7. self.check.project = self.project
  8. self.check.save()
  9. def test_it_works(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get("/checks/%s/status/" % self.check.code)
  12. doc = r.json()
  13. self.assertEqual(doc["status"], "new")
  14. self.assertTrue("never received a ping" in doc["status_text"])
  15. self.assertTrue("not received any pings yet" in doc["events"])
  16. def test_it_returns_events(self):
  17. p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1)
  18. self.check.status = "up"
  19. self.check.last_ping = p.created
  20. self.check.save()
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.get("/checks/%s/status/" % self.check.code)
  23. doc = r.json()
  24. self.assertEqual(doc["status"], "up")
  25. self.assertEqual(doc["updated"], p.created.strftime("%s.%f"))
  26. self.assertTrue("test-user-agent" in doc["events"])
  27. def test_it_omits_events(self):
  28. p = Ping.objects.create(owner=self.check, ua="test-user-agent", n=1)
  29. self.check.status = "up"
  30. self.check.last_ping = p.created
  31. self.check.save()
  32. timestamp = p.created.strftime("%s.%f")
  33. url = "/checks/%s/status/?u=%s" % (self.check.code, timestamp)
  34. self.client.login(username="[email protected]", password="password")
  35. r = self.client.get(url)
  36. doc = r.json()
  37. self.assertFalse("events" in doc)
  38. def test_it_allows_cross_team_access(self):
  39. self.bobs_profile.current_team = None
  40. self.bobs_profile.save()
  41. self.client.login(username="[email protected]", password="password")
  42. r = self.client.get("/checks/%s/status/" % self.check.code)
  43. self.assertEqual(r.status_code, 200)