forked from GithubBackups/healthchecks
Use assertRedirects() to test redirects.
This commit is contained in:
parent
be7feecbe2
commit
74c5e5d906
@ -1,5 +1,4 @@
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ class CheckTokenTestCase(TestCase):
|
|||||||
|
|
||||||
def test_it_redirects(self):
|
def test_it_redirects(self):
|
||||||
r = self.client.get("/accounts/check_token/alice/secret-token/")
|
r = self.client.get("/accounts/check_token/alice/secret-token/")
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
# After login, password should be unusable
|
# After login, password should be unusable
|
||||||
self.alice.refresh_from_db()
|
self.alice.refresh_from_db()
|
||||||
@ -26,11 +25,11 @@ class CheckTokenTestCase(TestCase):
|
|||||||
|
|
||||||
# Login again, when already authenticated
|
# Login again, when already authenticated
|
||||||
r = self.client.get("/accounts/check_token/alice/secret-token/")
|
r = self.client.get("/accounts/check_token/alice/secret-token/")
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
def test_it_redirects_bad_login(self):
|
def test_it_redirects_bad_login(self):
|
||||||
# Login with a bad token
|
# Login with a bad token
|
||||||
r = self.client.get("/accounts/check_token/alice/invalid-token/")
|
url = "/accounts/check_token/alice/invalid-token/"
|
||||||
assert r.status_code == 302
|
r = self.client.get(url, follow=True)
|
||||||
assert r.url.endswith(reverse("hc-login"))
|
self.assertRedirects(r, "/accounts/login/")
|
||||||
assert self.client.session["bad_link"]
|
self.assertContains(r, "incorrect or expired")
|
||||||
|
@ -21,7 +21,7 @@ class AddChannelTestCase(TestCase):
|
|||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url, form)
|
r = self.client.post(url, form)
|
||||||
|
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/integrations/")
|
||||||
assert Channel.objects.count() == 1
|
assert Channel.objects.count() == 1
|
||||||
|
|
||||||
def test_it_trims_whitespace(self):
|
def test_it_trims_whitespace(self):
|
||||||
|
@ -14,5 +14,5 @@ class AddCheckTestCase(TestCase):
|
|||||||
url = "/checks/add/"
|
url = "/checks/add/"
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url)
|
r = self.client.post(url)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
assert Check.objects.count() == 1
|
assert Check.objects.count() == 1
|
||||||
|
@ -19,7 +19,7 @@ class RemoveChannelTestCase(TestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url)
|
r = self.client.post(url)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/integrations/")
|
||||||
|
|
||||||
assert Channel.objects.count() == 0
|
assert Channel.objects.count() == 0
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class RemoveCheckTestCase(TestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url)
|
r = self.client.post(url)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
assert Check.objects.count() == 0
|
assert Check.objects.count() == 0
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class UpdateChannelTestCase(TestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post("/integrations/", data=payload)
|
r = self.client.post("/integrations/", data=payload)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/integrations/")
|
||||||
|
|
||||||
channel = Channel.objects.get(code=self.channel.code)
|
channel = Channel.objects.get(code=self.channel.code)
|
||||||
checks = channel.checks.all()
|
checks = channel.checks.all()
|
||||||
|
@ -19,7 +19,7 @@ class UpdateNameTestCase(TestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url, data=payload)
|
r = self.client.post(url, data=payload)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
check = Check.objects.get(code=self.check.code)
|
check = Check.objects.get(code=self.check.code)
|
||||||
assert check.name == "Alice Was Here"
|
assert check.name == "Alice Was Here"
|
||||||
|
@ -19,7 +19,7 @@ class UpdateTimeoutTestCase(TestCase):
|
|||||||
|
|
||||||
self.client.login(username="alice", password="password")
|
self.client.login(username="alice", password="password")
|
||||||
r = self.client.post(url, data=payload)
|
r = self.client.post(url, data=payload)
|
||||||
assert r.status_code == 302
|
self.assertRedirects(r, "/checks/")
|
||||||
|
|
||||||
check = Check.objects.get(code=self.check.code)
|
check = Check.objects.get(code=self.check.code)
|
||||||
assert check.timeout.total_seconds() == 3600
|
assert check.timeout.total_seconds() == 3600
|
||||||
|
Loading…
x
Reference in New Issue
Block a user