source: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt @ 5082

Last change on this file since 5082 was 5080, checked in by uli, 15 years ago

Update tests.

File size: 1.7 KB
RevLine 
[5080]1:mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs)
2********************************************************************
[5068]3
[5080]4.. module:: waeup.sirp.accesscodes.accesscodes
[5068]5
[5080]6Components that represent access codes and related.
[5068]7
[5080]8.. :doctest:
[5068]9
[5080]10Access codes are created as parts of batches. We therefore have to
11create a batch first.
[5068]12
[5080]13Here we create a batch of three entries, with a cost of ``12.12`` per
14code, the batch prefix ``APP``, batch number ``10``, creator ID
15``Fred`` and some arbitrary creation date:
16
[5068]17    >>> import datetime
18    >>> from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch
19    >>> batch = AccessCodeBatch(
20    ...   datetime.datetime(2009, 12, 23), 'Fred', 10, 'APP', 12.12, 3)
21
[5080]22Now we have three accesscodes stored in the batch:
[5068]23
[5080]24    >>> sorted(list(batch.items()))
25    [(u'0', <waeup.sirp...AccessCode object at 0x...), ...]
[5068]26
[5080]27As we can see, access codes entries can be found in a batch by their
28(stringified) serial number.
[5068]29
[5080]30Each accesscode has a representation:
[5068]31
[5080]32    >>> ac = batch['0']
33    >>> ac.representation
34    'APP-10-<10-DIGITS>'
[5068]35
[5080]36The main point about a batch is that it can act as a dictionary for
37the generated access codes:
[5068]38
[5080]39    >>> ac_codes = list(batch.values())
40    >>> [x.representation for x in ac_codes]
41    ['APP-10-...', 'APP-10-...', 'APP-10-...']
42
[5068]43`Accesscode` and `AccessCodeBatch` classes implement the respective
44interfaces:
45
46    >>> from waeup.sirp.accesscodes.accesscodes import (
47    ...   AccessCode, AccessCodeBatch)
48    >>> from waeup.sirp.accesscodes.interfaces import(
49    ...   IAccessCode, IAccessCodeBatch)
50    >>> from zope.interface.verify import verifyClass
51    >>> verifyClass(IAccessCode, AccessCode)
52    True
53
54    >>> verifyClass(IAccessCodeBatch, AccessCodeBatch)
55    True
Note: See TracBrowser for help on using the repository browser.