mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-08 06:30:05 +00:00
Improve tests
This commit is contained in:
parent
93c13b8221
commit
64a6245736
3 changed files with 42 additions and 10 deletions
|
@ -26,7 +26,7 @@ class GetFlipsTestCase(BaseTestCase):
|
|||
new_status="up",
|
||||
)
|
||||
|
||||
self.url = "/api/v1/checks/%s/flips/" % self.a1.code
|
||||
self.url = f"/api/v1/checks/{self.a1.code}/flips/"
|
||||
|
||||
def get(self, api_key="X" * 32, qs=""):
|
||||
return self.client.get(self.url + qs, HTTP_X_API_KEY=api_key)
|
||||
|
@ -45,6 +45,14 @@ class GetFlipsTestCase(BaseTestCase):
|
|||
self.assertEqual(flip["timestamp"], "2020-06-01T12:24:32+00:00")
|
||||
self.assertEqual(flip["up"], 1)
|
||||
|
||||
def test_it_works_with_unique_key(self):
|
||||
url = f"/api/v1/checks/{self.a1.unique_key}/flips/"
|
||||
r = self.client.get(url, HTTP_X_API_KEY="X" * 32)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
doc = r.json()
|
||||
self.assertEqual(len(doc["flips"]), 1)
|
||||
|
||||
def test_readonly_key_is_allowed(self):
|
||||
self.project.api_key_readonly = "R" * 32
|
||||
self.project.save()
|
||||
|
@ -67,9 +75,12 @@ class GetFlipsTestCase(BaseTestCase):
|
|||
def test_it_filters_by_start(self):
|
||||
r = self.get(qs="?start=1591014300") # 2020-06-01 12:25:00
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(r.json(), {"flips": []})
|
||||
|
||||
doc = r.json()
|
||||
self.assertEqual(doc["flips"], [])
|
||||
def test_it_filters_by_end(self):
|
||||
r = self.get(qs="?end=1591014180") # 2020-06-01 12:23:00
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(r.json(), {"flips": []})
|
||||
|
||||
def test_it_rejects_huge_start(self):
|
||||
r = self.get(qs="?start=12345678901234567890")
|
||||
|
|
26
hc/front/tests/test_index.py
Normal file
26
hc/front/tests/test_index.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from hc.api.models import Check
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
|
||||
class IndexTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.c1 = Check.objects.create(project=self.project)
|
||||
self.c2 = Check.objects.create(project=self.project)
|
||||
self.c3 = Check.objects.create(project=self.project)
|
||||
|
||||
def test_it_shows_projects(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get("/")
|
||||
|
||||
self.assertContains(r, "Alices Project")
|
||||
self.assertContains(r, "3 checks")
|
||||
self.assertContains(r, "status ic-up")
|
||||
|
||||
def test_it_shows_overall_down_status(self):
|
||||
self.c1.status = "down"
|
||||
self.c1.save()
|
||||
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get("/")
|
||||
self.assertContains(r, "status ic-down")
|
|
@ -17,15 +17,10 @@
|
|||
<div class="col-sm-6 col-md-4">
|
||||
<div class="panel project {% if project.id == last_project_id %}selected{% endif %}">
|
||||
<div class="status ic-{{ project.overall_status }}"></div>
|
||||
|
||||
<h4>{{ project }}</h4>
|
||||
|
||||
<div>
|
||||
{{ project.n_checks }}
|
||||
check{{ project.n_checks|pluralize }},
|
||||
|
||||
{{ project.n_channels }}
|
||||
integration{{ project.n_channels|pluralize }}
|
||||
{{ project.n_checks }} check{{ project.n_checks|pluralize }},
|
||||
{{ project.n_channels }} integration{{ project.n_channels|pluralize }}
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
{{ project.owner_email }}
|
||||
|
|
Loading…
Add table
Reference in a new issue