Changing email address and deleting account
===========================================

Before we can start we must set up our test environment by
creating an dummy survey.

>>> app = layer['portal']
>>> portal = layer['portal']
>>> from plone.testing.z2 import Browser
>>> browser = Browser(app)
>>> from euphorie.client.tests.utils import addSurvey
>>> from euphorie.client.tests.utils import addAccount
>>> from euphorie.client.tests.utils import MockMailFixture
>>> xml_survey="""\
... <sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
...    <title>Sector title</title>
...    <survey>
...      <title>Survey title</title>
...    </survey>
...  </sector>"""
>>> addSurvey(portal, xml_survey)
>>> account = addAccount()
>>> mail_fixture = MockMailFixture()
>>> from transaction import commit
>>> commit()

Login and request change
------------------------
We start our story by logging in and going to the account settings page.

>>> browser.open(portal.client.nl.absolute_url())
>>> browser.getLink("Login").click()
>>> browser.getControl(name="__ac_name").value="jane@example.com"
>>> browser.getControl(name="__ac_password:utf8:ustring").value=u"Øle".encode("utf-8")
>>> browser.getControl(name="next", index=0).click()

Lets request an email address change:

>>> browser.open("http://nohost/plone/client/nl/new-email")
>>> browser.getControl(name="form.widgets.loginname").value="jane@doe.name"
>>> browser.getControl(name="form.widgets.password").value=u"Øle".encode("utf-8")
>>> browser.getControl(name="form.buttons.save").click()
>>> browser.contents
'...Please confirm your new email...jane@doe.name...'


Confirm change
--------------

We should have received an email at jane@doe.name with a confirmation link:

>>> str(mail_fixture.storage[0][0][1])
'jane@doe.name'
>>> mail_body=mail_fixture.storage[0][0][0].as_string()
>>> import quopri
>>> import re
>>> url=re.search('(http://nohost/plone/client/confirm.*)', mail_body).group()
>>> url=quopri.decodestring(url)
>>> url
'http://nohost/plone/client/confirm-change?key=...'

When we click on the link the change is triggered:

>>> browser.open(url)
>>> browser.contents
'...Your email address has been updated...'
>>> browser.url
'http://nohost/plone/client/nl'


Logging in with new address
---------------------------

We can now login with our new address:

>>> browser.open('http://nohost/plone/client/nl/logout')
>>> browser.open('http://nohost/plone/client/nl')
>>> browser.getLink("Login").click()
>>> browser.getControl(name="__ac_name").value="jane@doe.name"
>>> browser.getControl(name="__ac_password:utf8:ustring").value=u"Øle".encode("utf-8")
>>> browser.getControl(name="next", index=0).click()
>>> '@@login' in browser.url
False
