Browse Source

De-tested

pull/81/head
Njira Perci 8 years ago
committed by Mayowa Falade
parent
commit
fca80f3e08
6 changed files with 18 additions and 74 deletions
  1. +3
    -10
      hc/api/tests/test_pause.py
  2. +6
    -25
      hc/api/tests/test_ping.py
  3. +3
    -0
      hc/api/tests/test_sendalerts.py
  4. +3
    -20
      hc/front/tests/test_add_channel.py
  5. +1
    -8
      hc/front/tests/test_add_check.py
  6. +2
    -11
      hc/front/tests/test_add_pushbover.py

+ 3
- 10
hc/api/tests/test_pause.py View File

@ -12,16 +12,7 @@ class PauseTestCase(BaseTestCase):
r = self.client.post(url, "", content_type="application/json",
HTTP_X_API_KEY="abc")
self.assertEqual(r.status_code, 200)
check.refresh_from_db()
self.assertEqual(check.status, "paused")
def test_it_only_allows_post(self):
url = "/api/v1/checks/1659718b-21ad-4ed1-8740-43afc6c41524/pause"
r = self.client.get(url, HTTP_X_API_KEY="abc")
self.assertEqual(r.status_code, 405)
### Assert the expected status code and check's status
def test_it_validates_ownership(self):
check = Check(user=self.bob, status="up")
@ -32,3 +23,5 @@ class PauseTestCase(BaseTestCase):
HTTP_X_API_KEY="abc")
self.assertEqual(r.status_code, 400)
### Test that it only allows post requests

+ 6
- 25
hc/api/tests/test_ping.py View File

@ -19,27 +19,6 @@ class PingTestCase(TestCase):
ping = Ping.objects.latest("id")
assert ping.scheme == "http"
def test_it_changes_status_of_paused_check(self):
self.check.status = "paused"
self.check.save()
r = self.client.get("/ping/%s/" % self.check.code)
assert r.status_code == 200
self.check.refresh_from_db()
assert self.check.status == "up"
def test_post_works(self):
csrf_client = Client(enforce_csrf_checks=True)
r = csrf_client.post("/ping/%s/" % self.check.code)
assert r.status_code == 200
def test_head_works(self):
csrf_client = Client(enforce_csrf_checks=True)
r = csrf_client.head("/ping/%s/" % self.check.code)
assert r.status_code == 200
assert Ping.objects.count() == 1
def test_it_handles_bad_uuid(self):
r = self.client.get("/ping/not-uuid/")
assert r.status_code == 400
@ -70,8 +49,7 @@ class PingTestCase(TestCase):
r = self.client.get("/ping/%s/" % self.check.code,
HTTP_X_FORWARDED_FOR=ip)
ping = Ping.objects.latest("id")
assert r.status_code == 200
assert ping.remote_addr == "1.1.1.1"
### Assert the expected response status code and ping's remote address
ip = "1.1.1.1, 2.2.2.2"
r = self.client.get("/ping/%s/" % self.check.code,
@ -84,9 +62,12 @@ class PingTestCase(TestCase):
r = self.client.get("/ping/%s/" % self.check.code,
HTTP_X_FORWARDED_PROTO="https")
ping = Ping.objects.latest("id")
assert r.status_code == 200
assert ping.scheme == "https"
### Assert the expected response status code and ping's scheme
def test_it_never_caches(self):
r = self.client.get("/ping/%s/" % self.check.code)
assert "no-cache" in r.get("Cache-Control")
### Test that when a ping is made a check with a paused status changes status
### Test that a post to a ping works
### Test that the csrf_client head works

+ 3
- 0
hc/api/tests/test_sendalerts.py View File

@ -28,6 +28,7 @@ class SendAlertsTestCase(BaseTestCase):
handled_names.append(args[0].name)
assert set(names) == set(handled_names)
### The above assert fails. Make it pass
def test_it_handles_grace_period(self):
check = Check(user=self.alice, status="up")
@ -37,3 +38,5 @@ class SendAlertsTestCase(BaseTestCase):
# Expect no exceptions--
Command().handle_one(check)
### Assert when Command's handle many that when handle_many should return True

+ 3
- 20
hc/front/tests/test_add_channel.py View File

@ -17,17 +17,6 @@ class AddChannelTestCase(BaseTestCase):
self.assertRedirects(r, "/integrations/")
assert Channel.objects.count() == 1
def test_team_access_works(self):
url = "/integrations/add/"
form = {"kind": "email", "value": "[email protected]"}
self.client.login(username="[email protected]", password="password")
self.client.post(url, form)
ch = Channel.objects.get()
# Added by bob, but should belong to alice (bob has team access)
self.assertEqual(ch.user, self.alice)
def test_it_trims_whitespace(self):
""" Leading and trailing whitespace should get trimmed. """
@ -40,15 +29,6 @@ class AddChannelTestCase(BaseTestCase):
q = Channel.objects.filter(value="[email protected]")
self.assertEqual(q.count(), 1)
def test_it_rejects_bad_kind(self):
url = "/integrations/add/"
form = {"kind": "dog", "value": "Lassie"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(url, form)
assert r.status_code == 400, r.status_code
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
kinds = ("email", "webhook", "pd", "pushover", "hipchat", "victorops")
@ -56,3 +36,6 @@ class AddChannelTestCase(BaseTestCase):
url = "/integrations/add_%s/" % frag
r = self.client.get(url)
self.assertContains(r, "Integration Settings", status_code=200)
### Test that the team access works
### Test that bad kinds don't work

+ 1
- 8
hc/front/tests/test_add_check.py View File

@ -11,11 +11,4 @@ class AddCheckTestCase(BaseTestCase):
self.assertRedirects(r, "/checks/")
assert Check.objects.count() == 1
def test_team_access_works(self):
url = "/checks/add/"
self.client.login(username="[email protected]", password="password")
self.client.post(url)
check = Check.objects.get()
# Added by bob, but should belong to alice (bob has team access)
self.assertEqual(check.user, self.alice)
### Test that team access works

+ 2
- 11
hc/front/tests/test_add_pushbover.py View File

@ -26,17 +26,6 @@ class AddPushoverTestCase(BaseTestCase):
r = self.client.get("/integrations/add_pushover/")
self.assertEqual(r.status_code, 404)
def test_it_validates_priority(self):
self.client.login(username="[email protected]", password="password")
session = self.client.session
session["po_nonce"] = "n"
session.save()
params = "pushover_user_key=a&nonce=n&prio=abc"
r = self.client.get("/integrations/add_pushover/?%s" % params)
assert r.status_code == 400
def test_it_validates_nonce(self):
self.client.login(username="[email protected]", password="password")
@ -47,3 +36,5 @@ class AddPushoverTestCase(BaseTestCase):
params = "pushover_user_key=a&nonce=INVALID&prio=0"
r = self.client.get("/integrations/add_pushover/?%s" % params)
assert r.status_code == 403
### Test that pushover validates priority

Loading…
Cancel
Save