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.

48 lines
1.8 KiB

  1. from hc.test import BaseTestCase
  2. class SetPasswordTestCase(BaseTestCase):
  3. def test_it_shows_form(self):
  4. token = self.profile.prepare_token("set-password")
  5. self.client.login(username="[email protected]", password="password")
  6. r = self.client.get("/accounts/set_password/%s/" % token)
  7. self.assertEqual(r.status_code, 200)
  8. self.assertContains(r, "Please pick a password")
  9. def test_it_checks_token(self):
  10. self.profile.prepare_token("set-password")
  11. self.client.login(username="[email protected]", password="password")
  12. # GET
  13. r = self.client.get("/accounts/set_password/invalid-token/")
  14. self.assertEqual(r.status_code, 400)
  15. # POST
  16. r = self.client.post("/accounts/set_password/invalid-token/")
  17. self.assertEqual(r.status_code, 400)
  18. def test_it_sets_password(self):
  19. token = self.profile.prepare_token("set-password")
  20. self.client.login(username="[email protected]", password="password")
  21. payload = {"password": "correct horse battery staple"}
  22. r = self.client.post("/accounts/set_password/%s/" % token, payload)
  23. self.assertEqual(r.status_code, 302)
  24. old_password = self.alice.password
  25. self.alice.refresh_from_db()
  26. self.assertNotEqual(self.alice.password, old_password)
  27. def test_post_checks_length(self):
  28. token = self.profile.prepare_token("set-password")
  29. self.client.login(username="[email protected]", password="password")
  30. payload = {"password": "abc"}
  31. r = self.client.post("/accounts/set_password/%s/" % token, payload)
  32. self.assertEqual(r.status_code, 200)
  33. old_password = self.alice.password
  34. self.alice.refresh_from_db()
  35. self.assertEqual(self.alice.password, old_password)