==============
 Address book
==============

Person data (name, address, ...) is stored inside an address book.

>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()

Create an address book
======================

As only managers are allowed to create address books we have to login:

>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
>>> browser.open('http://localhost/++skin++AddressBook/')

On the start page there is a link to add an address book:

>>> browser.getLink('address book').click()
>>> browser.getControl('title').value = 'test book'
>>> browser.getControl('Add').click()
>>> address_book_url = browser.url
>>> address_book_url
'http://localhost/++skin++AddressBook/AddressBook'


Edit address book's data
========================

The manager can also edit the address book's data. The edit form shows
the formerly entred data:

>>> browser.getLink('Edit address book').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook/@@edit.html'
>>> edit_address_book_url = browser.url
>>> browser.getControl('title').value
'test book'
>>> browser.getControl('title').value = 'ftest book'
>>> browser.getControl('Apply').click()

The edit form submits to itself and shows the stored data:

>>> browser.getControl('title').value
'ftest book'

Person list
===========

Initially there are no persons existing:

>>> browser.getLink('Person list').click()
>>> print browser.contents
<!DOCTYPE...
There are no persons entered yet, click on "Add person" to create one...

There is also an add link in the add menu to add a person:

>>> browser.getLink('person')
<Link text='person'
      url='http://localhost/++skin++AddressBook/AddressBook/@@addPerson.html'>


Editors
=======

Editors can add new persons:

>>> editor_browser = Browser()
>>> editor_browser.addHeader('Authorization', 'Basic editor:editor')
>>> editor_browser.open(address_book_url)
>>> editor_browser.getLink('person').click()

But there is no link to edit the address book's data (title)
because the editor is not allowed to do so:

>>> editor_browser.goBack()
>>> editor_browser.getLink('Edit address book')
Traceback (most recent call last):
LinkNotFoundError

Even opening the URL is not possible:

>>> editor_browser.open(edit_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Visitors
========

Visitors can only visit data but are not allowed to change anything:

>>> visitor_browser = Browser()
>>> visitor_browser.addHeader('Authorization', 'Basic visitor:visitor')
>>> visitor_browser.open(address_book_url)
>>> visitor_browser.getLink('person')
Traceback (most recent call last):
LinkNotFoundError

There is also no link to edit the address book's data (title)
because the visitor is not allowed to do so:

>>> visitor_browser.getLink('Edit address book')
Traceback (most recent call last):
LinkNotFoundError

Even opening the URL is not possible:

>>> visitor_browser.open(edit_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Delete all persons in addressbook
=================================

The Administrator is able to delete all persons in the address book on
the edit form.  But Editors and visitors are not allowed to do so, even
they know the URL.

Editor
------

>>> delete_address_book_url = address_book_url + '/@@delete_content.html'
>>> editor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden

Visitor
-------

>>> visitor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Administrator
-------------

Make sure there are some persons in the address book:

>>> from icemac.addressbook.testing import create_person
>>> ab = getRootFolder()['AddressBook']
>>> create_person(ab, ab, last_name=u'Tester', return_obj=False)
>>> create_person(ab, ab, last_name=u'Tester 2', return_obj=False)
>>> create_person(ab, ab, last_name=u'Tester 3', return_obj=False)

To delete all persons in the address bool, the Adminstrator has to
open the `edit address book` form and select the `Delete all persons
in address book` button there. An `are you sure` form is displayed:

>>> browser.getLink('Edit address book').click()
>>> browser.getControl('Delete all persons in address book').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook/@@delete_content.html'

When the adminstrator decides not to delete the persons he is led back
to the address book's edit form:

>>> print browser.contents
<!DOCTYPE ...
      <h1>Do you really want to delete all persons in this address book?</h1>...
                  <span>number of persons</span>...
    <span id="form-widgets-count"
          class="text-widget required int-field">3</span>...

>>> browser.getControl('No, cancel').click()
>>> browser.url == edit_address_book_url
True

When he decides to delete all persons he is led back to then empty
person list:

>>> browser.getControl('Delete all persons in address book').click()
>>> browser.getControl('Yes, delete').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook'
>>> print browser.contents
<...There are no persons entered yet, click on "Add person" to create one...


Delete whole address book
=========================

The Administrator is able to delete the whole address book on the edit
form.  But Editors and visitors are not allowed to do so, even they
know the URL.

Editor
------

>>> delete_address_book_url = address_book_url + '/@@delete_address_book.html'
>>> editor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden

Visitor
-------

>>> visitor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


Administrator
-------------

The Adminstrator has to open the `edit address book` form and select
the `Delete whole address book` button there. Then an `are you sure`
form is displayed:

>>> browser.getLink('Edit address book').click()
>>> browser.getControl('Delete whole address book').click()
>>> browser.url
'http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html'

When the adminstrator decides not to delete the address book he is led
back to the address book's edit form:

>>> browser.getControl('No, cancel').click()
>>> browser.url == edit_address_book_url
True

When he decides to delete the address book he is led back to the
administration form for all address books:


>>> browser.getControl('Delete whole address book').click()
>>> browser.getControl('Yes, delete').click()
>>> browser.url
'http://localhost/++skin++AddressBook/@@index.html'
>>> print browser.contents
<!DOCTYPE ...
There are no address books created yet, click on "Add address book" to create one...
