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.

41 lines
1.4 KiB

  1. from django.contrib.auth.hashers import make_password
  2. from hc.test import BaseTestCase
  3. class ChangeEmailTestCase(BaseTestCase):
  4. def test_it_shows_form(self):
  5. self.profile.token = make_password("foo", "change-email")
  6. self.profile.save()
  7. self.client.login(username="[email protected]", password="password")
  8. r = self.client.get("/accounts/change_email/foo/")
  9. self.assertContains(r, "Change Account's Email Address")
  10. def test_it_changes_password(self):
  11. self.profile.token = make_password("foo", "change-email")
  12. self.profile.save()
  13. self.client.login(username="[email protected]", password="password")
  14. payload = {"email": "[email protected]"}
  15. self.client.post("/accounts/change_email/foo/", payload)
  16. self.alice.refresh_from_db()
  17. self.assertEqual(self.alice.email, "[email protected]")
  18. self.assertFalse(self.alice.has_usable_password())
  19. def test_it_requires_unique_email(self):
  20. self.profile.token = make_password("foo", "change-email")
  21. self.profile.save()
  22. self.client.login(username="[email protected]", password="password")
  23. payload = {"email": "[email protected]"}
  24. r = self.client.post("/accounts/change_email/foo/", payload)
  25. self.assertContains(r, "[email protected] is not available")
  26. self.alice.refresh_from_db()
  27. self.assertEqual(self.alice.email, "[email protected]")