You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

9 years ago
9 years ago
9 years ago
  1. from django.contrib.auth.hashers import make_password
  2. from hc.test import BaseTestCase
  3. class CheckTokenTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(CheckTokenTestCase, self).setUp()
  6. self.profile.token = make_password("secret-token")
  7. self.profile.save()
  8. def test_it_shows_form(self):
  9. r = self.client.get("/accounts/check_token/alice/secret-token/")
  10. self.assertContains(r, "You are about to log in")
  11. def test_it_redirects(self):
  12. r = self.client.post("/accounts/check_token/alice/secret-token/")
  13. self.assertRedirects(r, "/checks/")
  14. # After login, token should be blank
  15. self.profile.refresh_from_db()
  16. self.assertEqual(self.profile.token, "")
  17. def test_it_redirects_already_logged_in(self):
  18. # Login
  19. self.client.login(username="[email protected]", password="password")
  20. # Login again, when already authenticated
  21. r = self.client.post("/accounts/check_token/alice/secret-token/")
  22. self.assertRedirects(r, "/checks/")
  23. def test_it_redirects_bad_login(self):
  24. # Login with a bad token
  25. url = "/accounts/check_token/alice/invalid-token/"
  26. r = self.client.post(url, follow=True)
  27. self.assertRedirects(r, "/accounts/login/")
  28. self.assertContains(r, "incorrect or expired")