Changeset 5080


Ignore:
Timestamp:
24 Mar 2010, 12:58:37 (15 years ago)
Author:
uli
Message:

Update tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt

    r5068 r5080  
    1 Accesscodes
    2 ***********
     1:mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs)
     2********************************************************************
    33
    4 :doctest:
     4.. module:: waeup.sirp.accesscodes.accesscodes
    55
    6 We can create accesscodes:
     6Components that represent access codes and related.
    77
    8     >>> from waeup.sirp.accesscodes.accesscodes import AccessCode
    9     >>> ac = AccessCode(0, 'APP', 12, '0123456789', 12.12)
    10     >>> ac.representation
    11     'APP-12-0123456789'
     8.. :doctest:
    129
    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:
     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:
    1616
    1717    >>> import datetime
     
    2020    ...   datetime.datetime(2009, 12, 23), 'Fred', 10, 'APP', 12.12, 3)
    2121
    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:
     22Now we have three accesscodes stored in the batch:
    2523
    26     >>> ac_codes = [x.representation for x in batch]
    27     >>> ac_codes
     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]
    2841    ['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
    4342
    4443`Accesscode` and `AccessCodeBatch` classes implement the respective
Note: See TracChangeset for help on using the changeset viewer.