Password views
--------------

Set up user.

    >>> from urllib import quote
    >>> uf = app.site.acl_users
    >>> _ignored = uf._doAddUser('mbr', 'mbrpw', ['Member'], [])

Create the browser object we'll be using.

    >>> from Testing.testbrowser import Browser
    >>> browser = Browser()
    >>> browser.handleErrors = False
    >>> browser.addHeader('Authorization', 'Basic mbr:mbrpw')

Cancel redirects users to the site root if no member area exists.

    >>> browser.open('http://localhost/site/@@password.html')
    >>> browser.getControl('[[cmf_default][Cancel]]').click()
    >>> browser.url
    'http://localhost/site'

Open the join form. Password field should be visible

    >>> browser.open("http://localhost/site/@@password.html")
    >>> browser.getControl(name='form.password').value == ''
    True
    >>> browser.getControl(name='form.password').value = 'new password'
    >>> browser.getControl(name='form.confirmation').value = 'is invalid'
    >>> browser.getControl(name='form.actions.change').click()
    >>> '[[cmf_default][Your password and confirmation' in browser.contents
    True
    >>> browser.getControl(name='form.password').value = 'new password'
    >>> browser.getControl(name='form.confirmation').value = 'new password'
    >>> browser.getControl(name='form.actions.change').click()
    >>> '[[[cmf_default][Your password has been changed.]]' in browser.contents
    True
    >>> uf.getUserById('mbr')._getPassword() == 'new password'
    True

Same with a non-ASCII password:

    >>> from ZPublisher.HTTPRequest import default_encoding
    >>> _NON_ASCII = u'\xc4\xd6\xdc password'
    >>> password = _NON_ASCII.encode(default_encoding)

    >>> browser = Browser() # XXX: how does this work with the old browser?
    >>> browser.handleErrors = False
    >>> browser.addHeader('Authorization', 'Basic mbr:new password')
    >>> browser.open("http://localhost/site/@@password.html")
    >>> browser.getControl(name='form.password').value = password
    >>> browser.getControl(name='form.confirmation').value = password
    >>> browser.getControl(name='form.actions.change').click()
    >>> '[[[cmf_default][Your password has been changed.]]' in browser.contents
    True

    >>> ptool = app.site.portal_properties
    >>> default_charset = ptool.getProperty('default_charset', None)
    >>> uf.getUserById('mbr')._getPassword() == _NON_ASCII.encode(default_charset)
    True
