Creating and publishing a survey
================================

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

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

Lets create an initial sector and login:

>>> from euphorie.content.tests.utils import createSector
>>> sector=createSector(portal, u"Bouw", "bouw", "bouw")
>>> from transaction import commit
>>> commit()
>>> browser.open("{site_url}/@@login?came_from={sector_url}".format(site_url=portal.absolute_url(), sector_url=sector.absolute_url()))
>>> browser.getControl(name="__ac_name").value="bouw"
>>> browser.getControl(name="__ac_password").value="bouw"
>>> browser.getForm(id="loginForm").submit()

Create a new sector
-------------------

The sectors homepage has a link to create a new sector:

>>> browser.getLink("add a new OiRA Tool").click()
>>> browser.getControl(name="form.widgets.title").value="Example survey"
>>> browser.getControl(name="form.buttons.save").click()
>>> "Item created" in browser.contents
True

Lets add a profile question:

>>> browser.getLink("Add Profile question").click()
>>> browser.getControl(name="form.widgets.title").value="Profile title"
>>> browser.getControl(name="form.widgets.question").value="Profile question"
>>> browser.getControl(name="form.widgets.description").value="Description of the profile question"
>>> browser.getControl(name="form.widgets.label_multiple_present").value="Question about multiple occurance"
>>> browser.getControl(name="form.widgets.label_single_occurance").value="Single occurance label"
>>> browser.getControl(name="form.widgets.label_multiple_occurances").value="Mutliple occurances label"
>>> browser.getControl(name="form.buttons.save").click()

Add a module and risk:

>>> browser.getLink("Add Module").click()
>>> browser.getControl(name="form.widgets.title").value="Module title"
>>> browser.getControl(name="form.widgets.description").value="Module description"
>>> browser.getControl(name="form.buttons.save").click()

>>> browser.getLink("Add Risk").click()
>>> browser.getControl(name="form.widgets.title").value="Risk title"
>>> browser.getControl(name="form.widgets.problem_description").value="There is a risk present"
>>> browser.getControl(name="form.widgets.description").value="Description of the risk"
>>> browser.getControl(name="form.buttons.save").click()

Publish survey
--------------

Now that we have a minimal survey we can publish it.
>>> browser.getLink('Updated').click()

We must confirm we want to publish:

>>> browser.contents
'...Are you sure you want to publish this OiRA Tool?...'
>>> browser.getControl(name="form.buttons.button_publish").click()
>>> browser.contents
'...Succesfully published the OiRA Tool. It can be accessed at...'
