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.

69 lines
2.4 KiB

  1. from hc.api.models import Check, Ping
  2. from hc.test import BaseTestCase
  3. class LastPingTestCase(BaseTestCase):
  4. def test_it_works(self):
  5. check = Check(user=self.alice)
  6. check.save()
  7. Ping.objects.create(owner=check, body="this is body")
  8. self.client.login(username="[email protected]", password="password")
  9. r = self.client.get("/checks/%s/last_ping/" % check.code)
  10. self.assertContains(r, "this is body", status_code=200)
  11. def test_it_shows_fail(self):
  12. check = Check(user=self.alice)
  13. check.save()
  14. Ping.objects.create(owner=check, fail=True)
  15. self.client.login(username="[email protected]", password="password")
  16. r = self.client.get("/checks/%s/last_ping/" % check.code)
  17. self.assertContains(r, "/fail", status_code=200)
  18. def test_it_shows_start(self):
  19. check = Check(user=self.alice)
  20. check.save()
  21. Ping.objects.create(owner=check, start=True)
  22. self.client.login(username="[email protected]", password="password")
  23. r = self.client.get("/checks/%s/last_ping/" % check.code)
  24. self.assertContains(r, "/start", status_code=200)
  25. def test_it_requires_user(self):
  26. check = Check.objects.create()
  27. r = self.client.get("/checks/%s/last_ping/" % check.code)
  28. self.assertEqual(r.status_code, 404)
  29. def test_it_accepts_n(self):
  30. check = Check(user=self.alice)
  31. check.save()
  32. # remote_addr, scheme, method, ua, body:
  33. check.ping("1.2.3.4", "http", "post", "tester", "foo-123", "success")
  34. check.ping("1.2.3.4", "http", "post", "tester", "bar-456", "success")
  35. self.client.login(username="[email protected]", password="password")
  36. r = self.client.get("/checks/%s/pings/1/" % check.code)
  37. self.assertContains(r, "foo-123", status_code=200)
  38. r = self.client.get("/checks/%s/pings/2/" % check.code)
  39. self.assertContains(r, "bar-456", status_code=200)
  40. def test_it_allows_cross_team_access(self):
  41. self.bobs_profile.current_team = None
  42. self.bobs_profile.save()
  43. check = Check(user=self.alice)
  44. check.save()
  45. Ping.objects.create(owner=check, body="this is body")
  46. self.client.login(username="[email protected]", password="password")
  47. r = self.client.get("/checks/%s/last_ping/" % check.code)
  48. self.assertEqual(r.status_code, 200)