=======================
 Address book overview
=======================

The overview contains a list of all addressbooks and allows to create
new addressbooks.

>>> from z3c.etestbrowser.wsgi import ExtendedTestBrowser as Browser
>>> browser = Browser()

Overview
========

The overview page requires an authenticated user with the
administrator role:

>>> browser.open('http://localhost/++skin++AddressBook/')
Traceback (most recent call last):
HTTPError: HTTP Error 401: Unauthorized

Before creating the first addressbook the overview page tells that
there are not addressbooks:

>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
>>> browser.handleErrors = False # XXX needed to test with z3c.pt
>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
<p>
  There are no address books created yet, click on "Add address book" to create one.
</p>...
>>> browser.handleErrors = True # XXX needed to test with z3c.pt


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

On the overview page is a link to add a new address book:

>>> from icemac.addressbook.testing import get_messages
>>> browser.getLink('address book').click()
>>> browser.getControl('title').value = 'test book'
>>> browser.getControl('Add').click()
>>> get_messages(browser)
['"test book" added.']
>>> address_book_url = browser.url
>>> address_book_url
'http://localhost/++skin++AddressBook/AddressBook'

View Addressbooks
=================

The overview page contains a list of the existing addressbooks
together with the number of entries inside:

>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
  <ul class="bullet">
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
      (0 items)
      <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
  </ul>
  ...

This view only displays addressbooks, when another object is in the
root folder it is not listed. (As there is no user interface to add an
object, I add it directly to the root folder.):

>>> from zope.container.btree import BTreeContainer
>>> getRootFolder()['btree'] = BTreeContainer()
>>> browser.open('http://localhost/++skin++AddressBook/')
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
  <li>
    <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
    (0 items)
    <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
  </li>
</ul>...

After creating a person one entry is displayed:

>>> from icemac.addressbook.testing import create_addressbook, create_person
>>> ab = create_addressbook('ab2', title=u'ab w/ content')
>>> create_person(ab, ab, u'Tester', return_obj=False)
>>> browser.reload()
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
   <li>
     <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>        (0 items)
     <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
   <li>
     <a href="http://localhost/++skin++AddressBook/ab2">ab w/ content</a>
     (1 item)
     <a href="http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html">Delete</a>
   </li>
</ul>...

>>> dummy = create_person(ab, ab, u'Tester2')
>>> browser.reload()
>>> print browser.contents
<!DOCTYPE ...
<ul class="bullet">
   <li>
     <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
     (0 items)
     <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
   </li>
   <li>
     <a href="http://localhost/++skin++AddressBook/ab2">ab w/ content</a>
     (2 items)
     <a href="http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html">Delete</a>
  </li>
</ul>...


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

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

Set up
------

Users are a bit harder to delete, so we add them here to show they can
get deleted as well:

>>> from icemac.addressbook.testing import create_user
>>> create_user(ab, ab, u'Hans', u'User', u'hans@user.de', u'asdf', ['Visitor'])
>>> create_user(ab, ab, u'Kurt', u'Utzr', u'kurt@utzr.ch', u'asdf', ['Editor'])


Editor
------

>>> delete_address_book_url = (
...     'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html')
>>> editor_browser = Browser()
>>> editor_browser.addHeader('Authorization', 'Basic editor:editor')
>>> editor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden

Visitor
-------

>>> visitor_browser = Browser()
>>> visitor_browser.addHeader('Authorization', 'Basic visitor:visitor')
>>> visitor_browser.open(delete_address_book_url)
Traceback (most recent call last):
HTTPError: HTTP Error 403: Forbidden


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

The Adminstrator has to select the `Delete` link. Then an `are you
sure` form is displayed:

>>> browser.getLink('Delete', index=1).click()
>>> browser.url
'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html'

When the adminstrator decides not to delete the address book he is led
back to the overview of all address books:

>>> browser.getControl('No, cancel').click()
>>> get_messages(browser)
['Deletion canceled.']
>>> browser.url
'http://localhost/++skin++AddressBook'

When he decides to delete the address book he is led back to the
overview as well:

>>> browser.getLink('Delete', index=1).click()
>>> browser.url
'http://localhost/++skin++AddressBook/ab2/@@delete_address_book.html'
>>> browser.getControl('Yes, delete').click()
>>> get_messages(browser)
['"ab w/ content" deleted.']
>>> browser.url
'http://localhost/++skin++AddressBook'
>>> print browser.contents
<!DOCTYPE ...
  <ul class="bullet">
    <li>
      <a href="http://localhost/++skin++AddressBook/AddressBook">test book</a>
      (0 items)
      <a href="http://localhost/++skin++AddressBook/AddressBook/@@delete_address_book.html">Delete</a>
    </li>
  </ul>...
