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.

49 lines
1.7 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_requires_user(self):
  12. check = Check.objects.create()
  13. r = self.client.get("/checks/%s/last_ping/" % check.code)
  14. self.assertEqual(r.status_code, 404)
  15. def test_it_accepts_n(self):
  16. check = Check(user=self.alice)
  17. check.save()
  18. # remote_addr, scheme, method, ua, body:
  19. check.ping("1.2.3.4", "http", "post", "tester", "foo-123")
  20. check.ping("1.2.3.4", "http", "post", "tester", "bar-456")
  21. self.client.login(username="[email protected]", password="password")
  22. r = self.client.get("/checks/%s/pings/1/" % check.code)
  23. self.assertContains(r, "foo-123", status_code=200)
  24. r = self.client.get("/checks/%s/pings/2/" % check.code)
  25. self.assertContains(r, "bar-456", status_code=200)
  26. def test_it_allows_cross_team_access(self):
  27. self.bobs_profile.current_team = None
  28. self.bobs_profile.save()
  29. check = Check(user=self.alice)
  30. check.save()
  31. Ping.objects.create(owner=check, body="this is body")
  32. self.client.login(username="[email protected]", password="password")
  33. r = self.client.get("/checks/%s/last_ping/" % check.code)
  34. self.assertEqual(r.status_code, 200)