Browse Source

Use assertRedirects() to test redirects.

pull/25/merge
Pēteris Caune 9 years ago
parent
commit
74c5e5d906
8 changed files with 13 additions and 14 deletions
  1. +6
    -7
      hc/accounts/tests/test_check_token.py
  2. +1
    -1
      hc/front/tests/test_add_channel.py
  3. +1
    -1
      hc/front/tests/test_add_check.py
  4. +1
    -1
      hc/front/tests/test_remove_channel.py
  5. +1
    -1
      hc/front/tests/test_remove_check.py
  6. +1
    -1
      hc/front/tests/test_update_channel.py
  7. +1
    -1
      hc/front/tests/test_update_name.py
  8. +1
    -1
      hc/front/tests/test_update_timeout.py

+ 6
- 7
hc/accounts/tests/test_check_token.py View File

@ -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/")
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")

+ 1
- 1
hc/front/tests/test_add_channel.py View File

@ -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):


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

@ -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

+ 1
- 1
hc/front/tests/test_remove_channel.py View File

@ -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


+ 1
- 1
hc/front/tests/test_remove_check.py View File

@ -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


+ 1
- 1
hc/front/tests/test_update_channel.py View File

@ -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()


+ 1
- 1
hc/front/tests/test_update_name.py View File

@ -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"


+ 1
- 1
hc/front/tests/test_update_timeout.py View File

@ -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…
Cancel
Save