1 | Accesscodes |
---|
2 | *********** |
---|
3 | |
---|
4 | :doctest: |
---|
5 | |
---|
6 | We 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 | |
---|
13 | We can create batches. Here we create a batch of three entries, with a |
---|
14 | cost of 12.12 per code, the batch prefix 'APP', batch number 12, |
---|
15 | creator 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 | |
---|
22 | The main point about a batch is that it can act as an iterator over |
---|
23 | the generated access codes. The codes are generated on-the-fly when |
---|
24 | iterating 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 | |
---|
30 | When we ask for the access codes again, we will get equal |
---|
31 | entries. 'Equal' means: we will get same representations, but not |
---|
32 | neccessarily 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 |
---|
45 | interfaces: |
---|
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 |
---|