Skip to content

Commit

Permalink
Merge pull request #10 from andela/ch-Front-tests-133846507
Browse files Browse the repository at this point in the history
[#133846507] front tests
  • Loading branch information
Awili Uzo committed Dec 5, 2016
2 parents 3137d9a + 9d9772d commit 341948b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ hc/local_settings.py
static-collected

.DS_Store
static/.DS_Store
static/.DS_Store
*.idea
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# healthchecks

[![CircleCI](https://circleci.com/gh/andela/healthchecks_turquoise/tree/master.svg?style=svg)](https://circleci.com/gh/andela/healthchecks_turquoise/tree/master) [![Code Climate](https://codeclimate.com/github/andela/healthchecks_turquoise/badges/gpa.svg)](https://codeclimate.com/github/andela/healthchecks_turquoise) [![Test Coverage](https://codeclimate.com/github/andela/healthchecks_turquoise/badges/coverage.svg)](https://codeclimate.com/github/andela/healthchecks_turquoise/coverage)

[![Coverage Status](https://coveralls.io/repos/github/andela/healthchecks_turquoise/badge.svg?branch=develop)](https://coveralls.io/github/andela/healthchecks_turquoise?branch=develop)
[![CircleCI](https://circleci.com/gh/andela/healthchecks_turquoise/tree/develop.svg?style=svg)](https://circleci.com/gh/andela/healthchecks_turquoise/tree/develop)
[![Code Climate](https://codeclimate.com/github/andela/healthchecks_turquoise/badges/gpa.svg)](https://codeclimate.com/github/andela/healthchecks_turquoise)
![Screenshot of Welcome page](/stuff/screenshots/welcome.png?raw=true "Welcome Page")

![Screenshot of My Checks page](/stuff/screenshots/my_checks.png?raw=true "My Checks Page")
Expand Down
19 changes: 19 additions & 0 deletions hc/api/tests/test_list_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,32 @@ def get(self):
def test_it_works(self):
r = self.get()
### Assert the response status code
self.assertEqual(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(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.url())
self.assertEqual(checks["Alice 1"]["last_ping"], self.now.isoformat())
self.assertEqual(checks["Alice 1"]["n_pings"], 1)
self.assertEqual(checks["Alice 1"]["status"], "new")
pause_url = "http://localhost:8000/api/v1/checks/%s/pause" % self.a1.code
self.assertEqual(checks["Alice 1"]["pause_url"], pause_url)

next_ping = self.now + td(seconds=3600)
self.assertEqual(checks["Alice 1"]["next_ping"], next_ping.isoformat())

self.assertEqual(checks["Alice 2"]["timeout"], 86400)
self.assertEqual(checks["Alice 2"]["grace"], 3600)
self.assertEqual(checks["Alice 2"]["ping_url"], self.a2.url())
self.assertEqual(checks["Alice 2"]["status"], "up")

def test_it_shows_only_users_checks(self):
bobs_check = Check(user=self.bob, name="Bob 1")
Expand All @@ -54,3 +72,4 @@ def test_it_shows_only_users_checks(self):
self.assertNotEqual(check["name"], "Bob 1")

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

17 changes: 17 additions & 0 deletions hc/front/tests/test_add_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,21 @@ def test_instructions_work(self):
self.assertContains(r, "Integration Settings", status_code=200)

### Test that the team access works
def test_team_access_works(self):
url = "/integrations/add/"
form = {"kind": "email", "value": "bob@example.org"}
self.client.login(username="bob@example.org", password="password")
self.client.post(url, form)

ch = Channel.objects.get()
self.assertEqual(ch.user, self.alice)

### Test that bad kinds don't work
def test_rejects_bad_kinds(self):
url = "/integrations/add/"
form = {"kind": "Mouse", "value": "Jerry"}

self.client.login(username="alice@example.org", password="password")
response = self.client.post(url, form)
self.assertEqual(400, response.status_code)

5 changes: 5 additions & 0 deletions hc/front/tests/test_add_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ def test_it_works(self):
assert Check.objects.count() == 1

### Test that team access works
def test_team_access_works(self):
url = "/checks/add/"
self.client.login(username="bob@example.org", password="password")
response = self.client.post(url)
self.assertRedirects(response, "/checks/")
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.test.utils import override_settings
from hc.api.models import Channel
from hc.test import BaseTestCase

from hc.api.models import Channel


@override_settings(PUSHOVER_API_TOKEN="token", PUSHOVER_SUBSCRIPTION_URL="url")
class AddPushoverTestCase(BaseTestCase):
Expand Down Expand Up @@ -37,4 +38,14 @@ def test_it_validates_nonce(self):
r = self.client.get("/integrations/add_pushover/?%s" % params)
assert r.status_code == 403

### Test that pushover validates priority
### Test that pushover validates priority
def test_it_validates_priority(self):
self.client.login(username="alice@example.org", password="password")

session = self.client.session
session["po_nonce"] = "n"
session.save()

params = "pushover_user_key=a&nonce=INVALID&prio=123"
response = self.client.get("/integrations/add_pushover/?%s" % params)
self.assertEqual(403, response.status_code)

0 comments on commit 341948b

Please sign in to comment.