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.

64 lines
2.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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, project=self.project)
  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, project=self.project)
  13. check.save()
  14. Ping.objects.create(owner=check, kind="fail")
  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, project=self.project)
  20. check.save()
  21. Ping.objects.create(owner=check, kind="start")
  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_accepts_n(self):
  26. check = Check(user=self.alice, project=self.project)
  27. check.save()
  28. # remote_addr, scheme, method, ua, body:
  29. check.ping("1.2.3.4", "http", "post", "tester", "foo-123", "success")
  30. check.ping("1.2.3.4", "http", "post", "tester", "bar-456", "success")
  31. self.client.login(username="[email protected]", password="password")
  32. r = self.client.get("/checks/%s/pings/1/" % check.code)
  33. self.assertContains(r, "foo-123", status_code=200)
  34. r = self.client.get("/checks/%s/pings/2/" % check.code)
  35. self.assertContains(r, "bar-456", status_code=200)
  36. def test_it_allows_cross_team_access(self):
  37. self.bobs_profile.current_team = None
  38. self.bobs_profile.save()
  39. check = Check(user=self.alice, project=self.project)
  40. check.save()
  41. Ping.objects.create(owner=check, body="this is body")
  42. self.client.login(username="[email protected]", password="password")
  43. r = self.client.get("/checks/%s/last_ping/" % check.code)
  44. self.assertEqual(r.status_code, 200)