Ignore:
Timestamp:
31 Mar 2010, 17:49:26 (15 years ago)
Author:
uli
Message:

Test the AccessCodePlugin?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt

    r5087 r5109  
    5959    >>> verifyClass(IAccessCodeBatch, AccessCodeBatch)
    6060    True
     61
     62Access codes without that are not part of a batch, will give strange
     63representations:
     64
     65    >>> ac = AccessCode(None, '9999999999', 12.12)
     66    >>> ac.representation
     67    '--<10-DIGITS>'
     68
     69Access code plugin
     70==================
     71
     72.. class:: AccessCodePlugin
     73
     74  .. attribute:: grok.implements(IWAeUPSIRPPluggable)
     75  .. attribute:: grok.name('accesscodes')
     76
     77  .. method:: setup(site, name, logger)
     78
     79     Create an accesscodebatch container in ``site``. Any events are
     80     logged to ``logger``.
     81
     82  .. method:: update(site, name, logger)
     83
     84     Check if ``site`` contains an accesscodebatch container and add
     85     it if missing. Any events are logged to ``logger``.
     86
     87  The AccessCodePlugin is available as a global named utility for the
     88  IWAeUPSIRPPluggable interface named ``accesscodes``.
     89
     90  It is looked up by a university instance when created.
     91
     92    >>> from zope.component import getUtility
     93    >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     94    >>> plugin = getUtility(IWAeUPSIRPPluggable, name='accesscodes')
     95    >>> plugin
     96    <waeup.sirp.accesscodes.accesscodes.AccessCodePlugin object at 0x...>
     97
     98  It provides a `setup()` and an `update()` method. Both have to be
     99  fed with a site object (the `IUniversity` instance to modify), a
     100  logger and a name.
     101
     102  We create a faked site and a logger:
     103
     104    >>> import logging
     105    >>> faked_site = dict()
     106    >>> logger = logging.getLogger('ac_test')
     107    >>> logger.setLevel(logging.DEBUG)
     108    >>> ch = logging.FileHandler('ac_tests.log', 'w')
     109    >>> ch.setLevel(logging.DEBUG)
     110    >>> logger.addHandler(ch)
     111
     112  Now we can install our stuff in the faked site:
     113
     114    >>> plugin.setup(faked_site, 'blah', logger)
     115
     116  The faked site now has an access code container:
     117
     118    >>> faked_site.keys()
     119    ['accesscodes']
     120
     121  The action is described in the log:
     122
     123    >>> print open('ac_tests.log', 'r').read()
     124    Installed container for access code batches.
     125
     126  We can also update an existing site, by calling `update()`:
     127
     128    >>> plugin.update(faked_site, 'blah', logger)
     129
     130  There was nothing to do for the updater:
     131
     132    >>> print open('ac_tests.log', 'r').read()
     133    Installed container for access code batches.
     134    AccessCodePlugin: Updating site at {'accesscodes'...: Nothing to do.
     135
     136  But if we remove the created batch container and call the updater, it
     137  will create a new one:
     138
     139    >>> del faked_site['accesscodes']
     140    >>> plugin.update(faked_site, 'blah', logger)
     141    >>> print open('ac_tests.log', 'r').read()
     142    Installed container for access code batches.
     143    AccessCodePlugin: Updating site at {'accesscodes'...: Nothing to do.
     144    Updating site at {}. Installing access codes.
     145    Installed container for access code batches.
     146
     147  Clean up:
     148
     149    >>> import os
     150    >>> os.unlink('ac_tests.log')
Note: See TracChangeset for help on using the changeset viewer.