====================
A functional doctest
====================

This is a full-blown functional test. The emphasis here is on testing what
the user may input and see, and the system is largely tested as a black box.
We use PloneTestCase to set up this test as well, so we have a full Plone site
to play with. We *can* inspect the state of the portal, e.g. using
self.portal and self.folder, but it is often frowned upon since you are not
treating the system as a black box. Also, if you, for example, log in or set
roles using calls like self.setRoles(), these are not reflected in the test
browser, which runs as a separate session.

Being a doctest, we can tell a story here.

First, we must perform some setup. We use the testbrowser that is shipped
with Five, as this provides proper Zope 2 integration. Most of the
documentation, though, is in the underlying zope.testbrower package.

    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> portal_url = self.portal.absolute_url()

The following is useful when writing and debugging testbrowser tests. It lets
us see all error messages in the error_log.

    >>> self.portal.error_log._ignored_exceptions = ()


    >>> from zope.component import queryUtility
    >>> from iccommunity.mailman.interfaces import IicCommunityMailman

    >>> chosen_transport = u"local"
    >>> local_util = queryUtility(IicCommunityMailman, chosen_transport)
    >>> local_util
    <iccommunity.mailman.mailman.icCommunityMailmanLocal...>

    >>> chosen_transport = u"ldap"
    >>> ldap_util = queryUtility(IicCommunityMailman, chosen_transport)
    >>> ldap_util
    <iccommunity.mailman.mailman.icCommunityMailmanLDAP...>

    >>> chosen_transport = u"test"
    >>> test_util = queryUtility(IicCommunityMailman, chosen_transport)
    >>> test_util
    <iccommunity.mailman.mailman.icCommunityMailmanTest...>

    >>> import os
    >>> from App import Common
    >>> pkg_home = Common.package_home({'__name__': 'iccommunity.mailman.tests'})
    >>> samplesdir = os.path.join(pkg_home, 'samples')

    >>> local_util.set_host('local://' + samplesdir + '/mailman')
    >>> local_util.set_host(samplesdir + '/mailman')
    >>> local_util.set_host('locals:///var/lib/mailman')
    Traceback (most recent call last):
        ...
    RuntimeError: Protocolo no soportado
    >>> local_util.set_host('ldap:///localhost/')
    Traceback (most recent call last):
        ...
    RuntimeError: Protocolo no soportado

    >>> ldap_util.set_host('ldap://localhost/')
    >>> ldap_util.set_host('ldaps://localhost/')
    >>> ldap_util.set_host('local:///var/lib/mailman')
    Traceback (most recent call last):
        ...
    RuntimeError: Protocolo no soportado

    >>> test_util.set_host('test://localhost/')
    >>> test_util.set_host('local:///var/lib/mailman')
    Traceback (most recent call last):
        ...
    RuntimeError: Protocolo no soportado
    >>> test_util.set_host('ldap:///var/lib/mailman')
    Traceback (most recent call last):
        ...
    RuntimeError: Protocolo no soportado
