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.

61 lines
2.5 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.objects.create(project=self.project)
  6. Ping.objects.create(owner=check, body="this is body")
  7. self.client.login(username="[email protected]", password="password")
  8. r = self.client.get("/checks/%s/last_ping/" % check.code)
  9. self.assertContains(r, "this is body", status_code=200)
  10. def test_it_shows_fail(self):
  11. check = Check.objects.create(project=self.project)
  12. Ping.objects.create(owner=check, kind="fail")
  13. self.client.login(username="[email protected]", password="password")
  14. r = self.client.get("/checks/%s/last_ping/" % check.code)
  15. self.assertContains(r, "/fail", status_code=200)
  16. def test_it_shows_start(self):
  17. check = Check.objects.create(project=self.project)
  18. Ping.objects.create(owner=check, kind="start")
  19. self.client.login(username="[email protected]", password="password")
  20. r = self.client.get("/checks/%s/last_ping/" % check.code)
  21. self.assertContains(r, "/start", status_code=200)
  22. def test_it_accepts_n(self):
  23. check = Check.objects.create(project=self.project)
  24. # remote_addr, scheme, method, ua, body:
  25. check.ping("1.2.3.4", "http", "post", "tester", "foo-123", "success")
  26. check.ping("1.2.3.4", "http", "post", "tester", "bar-456", "success")
  27. self.client.login(username="[email protected]", password="password")
  28. r = self.client.get("/checks/%s/pings/1/" % check.code)
  29. self.assertContains(r, "foo-123", status_code=200)
  30. r = self.client.get("/checks/%s/pings/2/" % check.code)
  31. self.assertContains(r, "bar-456", status_code=200)
  32. def test_it_allows_cross_team_access(self):
  33. self.bobs_profile.current_project = None
  34. self.bobs_profile.save()
  35. check = Check.objects.create(project=self.project)
  36. Ping.objects.create(owner=check, body="this is body")
  37. self.client.login(username="[email protected]", password="password")
  38. r = self.client.get("/checks/%s/last_ping/" % check.code)
  39. self.assertEqual(r.status_code, 200)
  40. def test_it_handles_missing_ping(self):
  41. check = Check.objects.create(project=self.project)
  42. self.client.login(username="[email protected]", password="password")
  43. r = self.client.get("/checks/%s/pings/123/" % check.code)
  44. self.assertContains(r, "No additional information is", status_code=200)