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

Last change on this file since 5077 was 5068, checked in by uli, 15 years ago

Add first accesscode (former PIN) data models.

File size: 1.7 KB
Line 
1Accesscodes
2***********
3
4:doctest:
5
6We can create accesscodes:
7
8    >>> from waeup.sirp.accesscodes.accesscodes import AccessCode
9    >>> ac = AccessCode(0, 'APP', 12, '0123456789', 12.12)
10    >>> ac.representation
11    'APP-12-0123456789'
12
13We can create batches. Here we create a batch of three entries, with a
14cost of 12.12 per code, the batch prefix 'APP', batch number 12,
15creator ID '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
22The main point about a batch is that it can act as an iterator over
23the generated access codes. The codes are generated on-the-fly when
24iterating over the batch for the first time:
25
26    >>> ac_codes = [x.representation for x in batch]
27    >>> ac_codes
28    ['APP-10-...', 'APP-10-...', 'APP-10-...']
29
30When we ask for the access codes again, we will get equal
31entries. 'Equal' means: we will get same representations, but not
32neccessarily the same objects:
33
34    >>> ac_codes2 = [x.representation for x in batch]
35    >>> ac_codes2 == ac_codes
36    True
37
38    >>> ac_codes[0] == ac_codes2[0]
39    True
40
41    >>> ac_codes[0] is ac_codes2[0]
42    False
43
44`Accesscode` and `AccessCodeBatch` classes implement the respective
45interfaces:
46
47    >>> from waeup.sirp.accesscodes.accesscodes import (
48    ...   AccessCode, AccessCodeBatch)
49    >>> from waeup.sirp.accesscodes.interfaces import(
50    ...   IAccessCode, IAccessCodeBatch)
51    >>> from zope.interface.verify import verifyClass
52    >>> verifyClass(IAccessCode, AccessCode)
53    True
54
55    >>> verifyClass(IAccessCodeBatch, AccessCodeBatch)
56    True
Note: See TracBrowser for help on using the repository browser.