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.

43 lines
1.6 KiB

  1. from hc.test import BaseTestCase
  2. class ChangeEmailTestCase(BaseTestCase):
  3. def test_it_requires_sudo_mode(self):
  4. self.client.login(username="[email protected]", password="password")
  5. r = self.client.get("/accounts/change_email/")
  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/change_email/")
  11. self.assertContains(r, "Change Account's Email Address")
  12. def test_it_updates_email(self):
  13. self.client.login(username="[email protected]", password="password")
  14. self.set_sudo_flag()
  15. payload = {"email": "[email protected]"}
  16. r = self.client.post("/accounts/change_email/", payload, follow=True)
  17. self.assertRedirects(r, "/accounts/change_email/done/")
  18. self.assertContains(r, "Email Address Updated")
  19. self.alice.refresh_from_db()
  20. self.assertEqual(self.alice.email, "[email protected]")
  21. self.assertFalse(self.alice.has_usable_password())
  22. # The user should have been logged out:
  23. self.assertNotIn("_auth_user_id", self.client.session)
  24. def test_it_requires_unique_email(self):
  25. self.client.login(username="[email protected]", password="password")
  26. self.set_sudo_flag()
  27. payload = {"email": "[email protected]"}
  28. r = self.client.post("/accounts/change_email/", payload)
  29. self.assertContains(r, "[email protected] is already registered")
  30. self.alice.refresh_from_db()
  31. self.assertEqual(self.alice.email, "[email protected]")