|
@ -15,12 +15,15 @@ class BadgeTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
sig = base64_hmac(str(self.project.badge_key), "foo", settings.SECRET_KEY) |
|
|
sig = base64_hmac(str(self.project.badge_key), "foo", settings.SECRET_KEY) |
|
|
sig = sig[:8] |
|
|
sig = sig[:8] |
|
|
self.svg_url = "/badge/%s/%s/foo.svg" % (self.project.badge_key, sig) |
|
|
|
|
|
self.json_url = "/badge/%s/%s/foo.json" % (self.project.badge_key, sig) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.svg_url = "/badge/%s/%s-2/foo.svg" % (self.project.badge_key, sig) |
|
|
|
|
|
self.json_url = "/badge/%s/%s-2/foo.json" % (self.project.badge_key, sig) |
|
|
|
|
|
self.with_late_url = "/badge/%s/%s/foo.json" % (self.project.badge_key, sig) |
|
|
|
|
|
self.shields_url = "/badge/%s/%s-2/foo.shields" % (self.project.badge_key, sig) |
|
|
|
|
|
|
|
|
def test_it_rejects_bad_signature(self): |
|
|
def test_it_rejects_bad_signature(self): |
|
|
r = self.client.get("/badge/%s/12345678/foo.svg" % self.project.badge_key) |
|
|
r = self.client.get("/badge/%s/12345678/foo.svg" % self.project.badge_key) |
|
|
assert r.status_code == 404 |
|
|
|
|
|
|
|
|
self.assertEqual(r.status_code, 404) |
|
|
|
|
|
|
|
|
def test_it_returns_svg(self): |
|
|
def test_it_returns_svg(self): |
|
|
r = self.client.get(self.svg_url) |
|
|
r = self.client.get(self.svg_url) |
|
@ -37,52 +40,24 @@ class BadgeTestCase(BaseTestCase): |
|
|
self.assertEqual(r["Access-Control-Allow-Origin"], "*") |
|
|
self.assertEqual(r["Access-Control-Allow-Origin"], "*") |
|
|
|
|
|
|
|
|
def test_it_handles_new(self): |
|
|
def test_it_handles_new(self): |
|
|
r = self.client.get(self.json_url) |
|
|
|
|
|
doc = r.json() |
|
|
|
|
|
self.assertEqual(doc["status"], "up") |
|
|
|
|
|
self.assertEqual(doc["total"], 1) |
|
|
|
|
|
self.assertEqual(doc["grace"], 0) |
|
|
|
|
|
self.assertEqual(doc["down"], 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_handles_started_but_down(self): |
|
|
|
|
|
|
|
|
doc = self.client.get(self.json_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"status": "up", "total": 1, "grace": 0, "down": 0}) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_ignores_started_when_down(self): |
|
|
self.check.last_start = now() |
|
|
self.check.last_start = now() |
|
|
self.check.tags = "foo" |
|
|
|
|
|
self.check.status = "down" |
|
|
self.check.status = "down" |
|
|
self.check.save() |
|
|
self.check.save() |
|
|
|
|
|
|
|
|
r = self.client.get(self.json_url) |
|
|
|
|
|
doc = r.json() |
|
|
|
|
|
self.assertEqual(doc["status"], "down") |
|
|
|
|
|
self.assertEqual(doc["total"], 1) |
|
|
|
|
|
self.assertEqual(doc["grace"], 0) |
|
|
|
|
|
self.assertEqual(doc["down"], 1) |
|
|
|
|
|
|
|
|
doc = self.client.get(self.json_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"status": "down", "total": 1, "grace": 0, "down": 1}) |
|
|
|
|
|
|
|
|
def test_it_shows_grace_badge(self): |
|
|
|
|
|
|
|
|
def test_it_treats_late_as_up(self): |
|
|
self.check.last_ping = now() - td(days=1, minutes=10) |
|
|
self.check.last_ping = now() - td(days=1, minutes=10) |
|
|
self.check.tags = "foo" |
|
|
|
|
|
self.check.status = "up" |
|
|
self.check.status = "up" |
|
|
self.check.save() |
|
|
self.check.save() |
|
|
|
|
|
|
|
|
r = self.client.get(self.json_url) |
|
|
|
|
|
doc = r.json() |
|
|
|
|
|
self.assertEqual(doc["status"], "late") |
|
|
|
|
|
self.assertEqual(doc["total"], 1) |
|
|
|
|
|
self.assertEqual(doc["grace"], 1) |
|
|
|
|
|
self.assertEqual(doc["down"], 0) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_shows_started_but_grace_badge(self): |
|
|
|
|
|
self.check.last_start = now() |
|
|
|
|
|
self.check.last_ping = now() - td(days=1, minutes=10) |
|
|
|
|
|
self.check.tags = "foo" |
|
|
|
|
|
self.check.status = "up" |
|
|
|
|
|
self.check.save() |
|
|
|
|
|
|
|
|
|
|
|
r = self.client.get(self.json_url) |
|
|
|
|
|
doc = r.json() |
|
|
|
|
|
self.assertEqual(doc["status"], "late") |
|
|
|
|
|
self.assertEqual(doc["total"], 1) |
|
|
|
|
|
self.assertEqual(doc["grace"], 1) |
|
|
|
|
|
self.assertEqual(doc["down"], 0) |
|
|
|
|
|
|
|
|
doc = self.client.get(self.json_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"status": "up", "total": 1, "grace": 1, "down": 0}) |
|
|
|
|
|
|
|
|
def test_it_handles_special_characters(self): |
|
|
def test_it_handles_special_characters(self): |
|
|
self.check.tags = "db@dc1" |
|
|
self.check.tags = "db@dc1" |
|
@ -94,3 +69,24 @@ class BadgeTestCase(BaseTestCase): |
|
|
|
|
|
|
|
|
r = self.client.get(url) |
|
|
r = self.client.get(url) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
self.assertEqual(r.status_code, 200) |
|
|
|
|
|
|
|
|
|
|
|
def test_late_mode_returns_late_status(self): |
|
|
|
|
|
self.check.last_ping = now() - td(days=1, minutes=10) |
|
|
|
|
|
self.check.status = "up" |
|
|
|
|
|
self.check.save() |
|
|
|
|
|
|
|
|
|
|
|
doc = self.client.get(self.with_late_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"status": "late", "total": 1, "grace": 1, "down": 0}) |
|
|
|
|
|
|
|
|
|
|
|
def test_late_mode_ignores_started_when_late(self): |
|
|
|
|
|
self.check.last_start = now() |
|
|
|
|
|
self.check.last_ping = now() - td(days=1, minutes=10) |
|
|
|
|
|
self.check.status = "up" |
|
|
|
|
|
self.check.save() |
|
|
|
|
|
|
|
|
|
|
|
doc = self.client.get(self.with_late_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"status": "late", "total": 1, "grace": 1, "down": 0}) |
|
|
|
|
|
|
|
|
|
|
|
def test_it_returns_shields_json(self): |
|
|
|
|
|
doc = self.client.get(self.shields_url).json() |
|
|
|
|
|
self.assertEqual(doc, {"label": "foo", "message": "up", "color": "success"}) |