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

Last change on this file since 5099 was 5087, checked in by uli, 14 years ago

Update tests.

File size: 1.9 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','APP', 12.12, 3, num=10)
21
22The entries of a batch have to be created manually. This is, because
23we cannot add persistent objects in a still not persisted container:
24
25    >>> batch.createEntries()
26
27Now we have three accesscodes stored in the batch:
28
29    >>> sorted(list(batch.items()))
30    [(u'0', <waeup.sirp...AccessCode object at 0x...), ...]
31
32As we can see, access codes entries can be found in a batch by their
33(stringified) serial number.
34
35Each accesscode has a representation:
36
37    >>> ac = batch['0']
38    >>> ac.representation
39    'APP-10-<10-DIGITS>'
40
41The main point about a batch is that it can act as a dictionary for
42the generated access codes:
43
44    >>> ac_codes = list(batch.values())
45    >>> [x.representation for x in ac_codes]
46    ['APP-10-...', 'APP-10-...', 'APP-10-...']
47
48`Accesscode` and `AccessCodeBatch` classes implement the respective
49interfaces:
50
51    >>> from waeup.sirp.accesscodes.accesscodes import (
52    ...   AccessCode, AccessCodeBatch)
53    >>> from waeup.sirp.accesscodes.interfaces import(
54    ...   IAccessCode, IAccessCodeBatch)
55    >>> from zope.interface.verify import verifyClass
56    >>> verifyClass(IAccessCode, AccessCode)
57    True
58
59    >>> verifyClass(IAccessCodeBatch, AccessCodeBatch)
60    True
Note: See TracBrowser for help on using the repository browser.