Sectors act as accounts
=======================

Before we can start we must set up our test environment:

>>> app = layer['portal']
>>> portal = layer['portal']
>>> from plone.testing.z2 import Browser
>>> browser = Browser(layer['app'])
>>> browser.handleErrors=False
>>> portal.error_log._ignored_exceptions=("Unauthorized")

When we first visit the Plone site we are not logged in. Lets start
by logging in as the site owner:

>>> from plone.app.testing.interfaces import SITE_OWNER_NAME
>>> from plone.app.testing.interfaces import SITE_OWNER_PASSWORD
>>> browser.open(portal.absolute_url()+"/@@login")
>>> browser.getControl(name="__ac_name").value=SITE_OWNER_NAME
>>> browser.getControl(name="__ac_password").value=SITE_OWNER_PASSWORD
>>> browser.getForm(id="loginForm").submit()

We are now logged as site administrator:

>>> browser.url==portal.absolute_url()+"/sectors/"
True
>>> "You have been logged in." in browser.contents
True

Lets go to the user management screen and add a user:

>>> browser.getLink("Netherlands").click()
>>> browser.getLink("User management").click()
>>> browser.getLink("Add new sector").click()
>>> browser.getControl(name="form.widgets.title").value="Fine Dining"
>>> browser.getControl(name="form.widgets.login").value="dining"
>>> browser.getControl(name="form.widgets.password").value="S3cr3t!"
>>> browser.getControl(name="form.widgets.password.confirm").value="S3cr3t!"
>>> browser.getControl(name="form.widgets.contact_name").value="John Doe"
>>> browser.getControl(name="form.widgets.contact_email").value="john@example.com"
>>> browser.getControl(name="form.buttons.save").click()
>>> browser.url
'http://nohost/plone/sectors/nl/fine-dining'

Now that the sector has been created we can logout the portal owner:

>>> from zExceptions import Unauthorized
>>> try:
...    browser.open(portal.absolute_url()+"/@@logout")
... except Unauthorized:
...     pass

We can now login using the new sector account. Logging in as a sector will
also automatically redirect to the homepage of the sector:

>>> browser.open(portal.absolute_url()+"/@@login")
>>> browser.getControl(name="__ac_name").value="dining"
>>> browser.getControl(name="__ac_password").value="S3cr3t!"
>>> browser.getForm(id="loginForm").submit()
>>> "You have been logged in." in browser.contents
True
>>> browser.url
'http://nohost/plone/sectors/nl/fine-dining'
