|
from django.contrib.auth.hashers import make_password
|
|
|
|
from hc.test import BaseTestCase
|
|
|
|
|
|
class ChangeEmailTestCase(BaseTestCase):
|
|
def test_it_shows_form(self):
|
|
self.profile.token = make_password("foo", "change-email")
|
|
self.profile.save()
|
|
|
|
self.client.login(username="[email protected]", password="password")
|
|
|
|
r = self.client.get("/accounts/change_email/foo/")
|
|
self.assertContains(r, "Change Account's Email Address")
|
|
|
|
def test_it_changes_password(self):
|
|
self.profile.token = make_password("foo", "change-email")
|
|
self.profile.save()
|
|
|
|
self.client.login(username="[email protected]", password="password")
|
|
|
|
payload = {"email": "[email protected]"}
|
|
self.client.post("/accounts/change_email/foo/", payload)
|
|
|
|
self.alice.refresh_from_db()
|
|
self.assertEqual(self.alice.email, "[email protected]")
|
|
self.assertFalse(self.alice.has_usable_password())
|
|
|
|
def test_it_requires_unique_email(self):
|
|
self.profile.token = make_password("foo", "change-email")
|
|
self.profile.save()
|
|
|
|
self.client.login(username="[email protected]", password="password")
|
|
|
|
payload = {"email": "[email protected]"}
|
|
r = self.client.post("/accounts/change_email/foo/", payload)
|
|
self.assertContains(r, "[email protected] is already registered")
|
|
|
|
self.alice.refresh_from_db()
|
|
self.assertEqual(self.alice.email, "[email protected]")
|