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
Line 
1:mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs)
2********************************************************************
3
4.. module:: waeup.sirp.accesscodes.accesscodes
5
6Components that represent access codes and related.
7
8.. :doctest:
9
10Access codes are created as parts of batches. We therefore have to
11create a batch first.
12
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
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
22Now we have three accesscodes stored in the batch:
23
24    >>> sorted(list(batch.items()))
25    [(u'0', <waeup.sirp...AccessCode object at 0x...), ...]
26
27As we can see, access codes entries can be found in a batch by their
28(stringified) serial number.
29
30Each accesscode has a representation:
31
32    >>> ac = batch['0']
33    >>> ac.representation
34    'APP-10-<10-DIGITS>'
35
36The main point about a batch is that it can act as a dictionary for
37the generated access codes:
38
39    >>> ac_codes = list(batch.values())
40    >>> [x.representation for x in ac_codes]
41    ['APP-10-...', 'APP-10-...', 'APP-10-...']
42
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.