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.

83 lines
2.9 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. self.url = "/checks/%s/status/" % self.check.code
  9. def test_it_works(self):
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  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(self.url)
  23. doc = r.json()
  24. self.assertEqual(doc["status"], "up")
  25. self.assertEqual(doc["updated"], str(p.created.timestamp()))
  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 = str(p.created.timestamp())
  33. url = self.url + "?u=%s" % 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.client.login(username="[email protected]", password="password")
  40. r = self.client.get(self.url)
  41. self.assertEqual(r.status_code, 200)
  42. def test_it_handles_manual_resume(self):
  43. self.check.status = "paused"
  44. self.check.manual_resume = True
  45. self.check.save()
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.get(self.url)
  48. doc = r.json()
  49. self.assertEqual(doc["status"], "paused")
  50. self.assertIn("will ignore pings until resumed", doc["status_text"])
  51. self.assertIn("resume-btn", doc["status_text"])
  52. def test_resume_requires_rw_access(self):
  53. self.bobs_membership.rw = False
  54. self.bobs_membership.save()
  55. self.check.status = "paused"
  56. self.check.manual_resume = True
  57. self.check.save()
  58. self.client.login(username="[email protected]", password="password")
  59. r = self.client.get(self.url)
  60. doc = r.json()
  61. self.assertEqual(doc["status"], "paused")
  62. self.assertIn("will ignore pings until resumed", doc["status_text"])
  63. self.assertNotIn("resume-btn", doc["status_text"])