Skip to content

Commit

Permalink
Fixed: finished tests for list_check [Fixes #145028637]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kachulio1 committed May 24, 2017
1 parent 4ae2864 commit 7052fc1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions hc/api/tests/test_list_checks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from datetime import timedelta as td
from django.utils.timezone import now
from django.conf import settings


from hc.api.models import Check
from hc.test import BaseTestCase
Expand Down Expand Up @@ -32,16 +34,41 @@ def get(self):
return self.client.get("/api/v1/checks/", HTTP_X_API_KEY="abc")

def test_it_works(self):

r = self.get()

### Assert the response status code
self.assertTrue(r.status_code == 200)

doc = r.json()
self.assertTrue("checks" in doc)


checks = {check["name"]: check for check in doc["checks"]}
### Assert the expected length of checks

self.assertEqual(len(doc["checks"]), 2)

### Assert the checks Alice 1 and Alice 2's timeout, grace, ping_url, status,
### last_ping, n_pings and pause_url
self.assertEqual(checks['Alice 1']['timeout'],3600)
self.assertEqual(checks['Alice 1']['grace'], 900)
self.assertEqual(checks['Alice 1']['ping_url'], self.a1.to_dict()['ping_url'])
self.assertEqual(checks['Alice 1']['status'], "new")
self.assertEqual(checks['Alice 1']['last_ping'], self.now.isoformat())
self.assertEqual(checks['Alice 1']['n_pings'],self.a1.to_dict()['n_pings'])
self.assertEqual(checks['Alice 1']['pause_url'],self.a1.to_dict()['pause_url'] )

self.assertEqual(checks['Alice 2']['timeout'], 86400)
self.assertEqual(checks['Alice 2']['grace'], 3600)
self.assertEqual(checks['Alice 2']['ping_url'],self.a2.to_dict()['ping_url'])
self.assertEqual(checks['Alice 2']['status'], "up")
self.assertEqual(checks['Alice 2']['last_ping'], self.a2.to_dict()['last_ping'])
self.assertEqual(checks['Alice 2']['n_pings'], self.a2.to_dict()['n_pings'])
self.assertEqual(checks['Alice 2']['pause_url'], self.a2.to_dict()['pause_url'])




def test_it_shows_only_users_checks(self):
bobs_check = Check(user=self.bob, name="Bob 1")
Expand All @@ -53,4 +80,9 @@ def test_it_shows_only_users_checks(self):
for check in data["checks"]:
self.assertNotEqual(check["name"], "Bob 1")


### Test that it accepts an api_key in the request

def test_it_accepts_an_api_key_in_request(self):
r = self.get()
self.assertTrue('HTTP_X_API_KEY' in r.request)

0 comments on commit 7052fc1

Please sign in to comment.