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.

40 lines
1.4 KiB

  1. from hc.test import BaseTestCase
  2. class SetPasswordTestCase(BaseTestCase):
  3. def test_it_requires_sudo_mode(self):
  4. self.client.login(username="[email protected]", password="password")
  5. r = self.client.get("/accounts/set_password/")
  6. self.assertContains(r, "We have sent a confirmation code")
  7. def test_it_shows_form(self):
  8. self.client.login(username="[email protected]", password="password")
  9. self.set_sudo_flag()
  10. r = self.client.get("/accounts/set_password/")
  11. self.assertContains(r, "Please pick a password")
  12. def test_it_sets_password(self):
  13. self.client.login(username="[email protected]", password="password")
  14. self.set_sudo_flag()
  15. payload = {"password": "correct horse battery staple"}
  16. r = self.client.post("/accounts/set_password/", payload)
  17. self.assertRedirects(r, "/accounts/profile/")
  18. old_password = self.alice.password
  19. self.alice.refresh_from_db()
  20. self.assertNotEqual(self.alice.password, old_password)
  21. def test_post_checks_length(self):
  22. self.client.login(username="[email protected]", password="password")
  23. self.set_sudo_flag()
  24. payload = {"password": "abc"}
  25. r = self.client.post("/accounts/set_password/", payload)
  26. self.assertEqual(r.status_code, 200)
  27. old_password = self.alice.password
  28. self.alice.refresh_from_db()
  29. self.assertEqual(self.alice.password, old_password)