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.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
@ -14,7 +13,7 @@ class CheckTokenTestCase(TestCase):
|
||||
|
||||
def test_it_redirects(self):
|
||||
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
|
||||
self.alice.refresh_from_db()
|
||||
@ -26,11 +25,11 @@ class CheckTokenTestCase(TestCase):
|
||||
|
||||
# Login again, when already authenticated
|
||||
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):
|
||||
# Login with a bad token
|
||||
r = self.client.get("/accounts/check_token/alice/invalid-token/")
|
||||
assert r.status_code == 302
|
||||
assert r.url.endswith(reverse("hc-login"))
|
||||
assert self.client.session["bad_link"]
|
||||
url = "/accounts/check_token/alice/invalid-token/"
|
||||
r = self.client.get(url, follow=True)
|
||||
self.assertRedirects(r, "/accounts/login/")
|
||||
self.assertContains(r, "incorrect or expired")
|
||||
|
@ -21,7 +21,7 @@ class AddChannelTestCase(TestCase):
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url, form)
|
||||
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/integrations/")
|
||||
assert Channel.objects.count() == 1
|
||||
|
||||
def test_it_trims_whitespace(self):
|
||||
|
@ -14,5 +14,5 @@ class AddCheckTestCase(TestCase):
|
||||
url = "/checks/add/"
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/checks/")
|
||||
assert Check.objects.count() == 1
|
||||
|
@ -19,7 +19,7 @@ class RemoveChannelTestCase(TestCase):
|
||||
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/integrations/")
|
||||
|
||||
assert Channel.objects.count() == 0
|
||||
|
||||
|
@ -18,7 +18,7 @@ class RemoveCheckTestCase(TestCase):
|
||||
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/checks/")
|
||||
|
||||
assert Check.objects.count() == 0
|
||||
|
||||
|
@ -25,7 +25,7 @@ class UpdateChannelTestCase(TestCase):
|
||||
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post("/integrations/", data=payload)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/integrations/")
|
||||
|
||||
channel = Channel.objects.get(code=self.channel.code)
|
||||
checks = channel.checks.all()
|
||||
|
@ -19,7 +19,7 @@ class UpdateNameTestCase(TestCase):
|
||||
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url, data=payload)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/checks/")
|
||||
|
||||
check = Check.objects.get(code=self.check.code)
|
||||
assert check.name == "Alice Was Here"
|
||||
|
@ -19,7 +19,7 @@ class UpdateTimeoutTestCase(TestCase):
|
||||
|
||||
self.client.login(username="alice", password="password")
|
||||
r = self.client.post(url, data=payload)
|
||||
assert r.status_code == 302
|
||||
self.assertRedirects(r, "/checks/")
|
||||
|
||||
check = Check.objects.get(code=self.check.code)
|
||||
assert check.timeout.total_seconds() == 3600
|
||||
|
Loading…
x
Reference in New Issue
Block a user