Browsing the access-code related UI components
**********************************************

Here we visit the access-code related parts of a WAeUP SIRP site using
a virtual browser.

:Test-Layer: functional

Preliminaries
=============

Before we can do anything, we have to create a university site:

    >>> from zope.testbrowser.testing import Browser
    >>> browser = Browser()
    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    >>> browser.handleErrors = False
    >>> root = getRootFolder()

    >>> from waeup.sirp.app import University
    >>> u = University()
    >>> root['myuniversity'] = u

Access-code management screen
=============================

For users that have the right to manage access-code related stuff, the
home page of a `University` instance provides a link to the
access-code management screen. In the beginning, there are naturally
no batches available:

    >>> browser.open('http://localhost/myuniversity')
    >>> browser.getLink('Manage access-codes').click()
    >>> print browser.contents
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    ...
    <h2>Access Code Batches</h2>
    ...
    ... The following batches are available:
    ...No batches yet...
    ...

Adding batches
==============

We can add a batch of access-codes using a button displayed in the
action bar:

    >>> browser.getLink('Add Scratch Card Batch').click()

The add screen shows a form where we have to enter a prefix, the
number of access codes to be generated and the costs for each card.

    >>> browser.getControl(name='form.batch_prefix').value = 'APP'
    >>> browser.getControl(name='form.entry_num').value = '5'
    >>> browser.getControl(name='form.cost').value = '12.12'

If we click 'cancel' afterwards, the whole process will be cancelled
and we'll be redirected to the management screen:

    >>> browser.getControl('Cancel').click()
    >>> browser.url
    'http://localhost/myuniversity/accesscodes'

    >>> 'Batch creation cancelled' in browser.contents
    True

Now let's try again and this time we finish the procedure by clicking
'Create batch' in the form:

    >>> browser.getLink('Add Scratch Card Batch').click()
    >>> browser.getControl(name='form.batch_prefix').value = 'APP'
    >>> browser.getControl(name='form.entry_num').value = '5'
    >>> browser.getControl(name='form.cost').value = '12.12'
    >>> browser.getControl('Create batch').click()

We're also redirected to the management screen, with a notice about
the freshly created batch:

    >>> print browser.contents
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    ...
    <h2>Access Code Batches</h2>
    ...
    ... The following batches are available:
    ...APP
    ...-
    ...1
    ...
    ...5
    .../
    ...0
    ...
    ...12.12...
    ...zope.mgr...
    ...

which means: there exists a batch named ``APP-1`` with 5 entries of
which 0 have been devalidated, each one costs ``12.12`` and the batch
was created by ``zope.mgr``.
