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.

35 lines
1.2 KiB

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