Ignore:
Timestamp:
13 Apr 2010, 15:48:05 (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

    r5138 r5150  
    4646   themselves. They have to be stored inside a persistent object (like
    4747   :class:`AccessCodeBatch`) to be kept.
     48
     49   Access-codes can have three states: unused, used, and
     50   disabled. While still unused but enabled access-codes are reflected
     51   by an empty ``invalidation_date`` (set to ``None``), an already
     52   used (invalidated) code provides an invalidation date.
     53
     54   In case of misuse or similar cases access-codes can also be
     55   completely disabled by setting the ``disabled`` attribute to
     56   ``True``.
    4857
    4958   The class implements
     
    98107      Python datetime when the access code was invalidated, or
    99108      ``None``. ``None`` by default.
     109
     110      If an access-code is disabled, this attribute contains the
     111      datetime of disabling.
     112
     113      Read-only attribute. Only batches are supposed to set this value.
     114
     115   .. attribute:: disabled
     116
     117      Boolean, ``False`` by default. When set to ``True``, this
     118      access-code should not be used any more.
    100119
    101120      Read-only attribute. Only batches are supposed to set this value.
     
    187206      When a code cannot be found :exc:`KeyError` is raised.
    188207
     208   .. method:: getAccessCodeForStudentId(student_id)
     209
     210      Get the :class:`AccessCode` object for the given
     211      ``student_id``.
     212
     213      Certain single access codes can be accessed inside a batch by
     214      their student_id. The student_id must be some string; ``None``
     215      is not a valid value.
     216
     217      When a code cannot be found :exc:`KeyError` is raised.
     218
    189219   .. method:: addAccessCode(serial_num, random_num)
    190220
     
    202232      :class:`AccessCode` entry.
    203233
     234   .. method:: disable(ac_id, user_id)
     235
     236      Disable the access-code with ID ``ac_id``.
     237
     238     ``user_id`` is the user ID of the user triggering the
     239      process. Already disabled ACs are left untouched.
     240
     241      Sets also the ``student_id`` and ``invalidation_date``
     242      attributes of the respective :class:`AccessCode` entry. While
     243      ``student_id`` is set to the given ``user_id``,
     244      ``invalidation_date`` is set to current datetime.
     245
     246      Disabled access codes are supposed not to be used any more at
     247      all.
     248
     249   .. method:: enable(ac_id)
     250
     251      (Re-)enable the access-code with ID ``ac_id``.
     252
     253      This leaves the given AC in state ``unused``. Already enabled
     254      ACs are left untouched.
     255
     256      Sets ``student_id`` and ``invalidation_date`` values of the
     257      respective :class:`AccessCode` entry to ``None``.
     258
    204259   .. method:: createCSVLogFile()
    205260
     
    218273
    219274      Returns name of created file.
     275
     276   .. method:: search(searchterm, searchtype)
     277
     278      Search the batch for entries that comply with ``searchterm`` and
     279      ``searchtype``.
     280
     281      ``searchtype`` must be one of ``serial``, ``pin``, or
     282      ``stud_id`` and specifies, what kind of data is contained in the
     283      ``searchterm``.
     284
     285      - ``serial`` looks for the AC with the ``serial_batch`` set to
     286        the given (integer) number in ``searchterm``. Here
     287        ``searchterm`` must be an int number.
     288
     289      - ``pin`` looks for the AC with the ``representation`` set to
     290        the given string in ``searchterm``. Here ``searchterm`` must
     291        be a string containing the full AC-ID like
     292        ``APP-1-0123456789``.
     293
     294      - ``stud_id`` looks for the AC with the ``student_id`` set to
     295        the given string in ``searchterm``. Here ``searchterm`` must
     296        be a string containing the full student ID.
     297
     298      Lookup is done via local BTrees and therefore pretty fast.
     299
     300      Returns a list of access-codes found or empty list.
    220301
    221302
     
    288369    'some_user_id'
    289370
     371Getting a single entry by student_id:
     372
     373    >>> batch.getAccessCodeForStudentId('some_user_id')
     374    <waeup.sirp...AccessCode object at 0x...>
     375
     376Non-existent values will cause a :exc:`KeyError`:
     377
     378    >>> batch.getAccessCodeForStudentId('non-existing')
     379    Traceback (most recent call last):
     380    ...
     381    KeyError: 'non-existing'
     382
     383Already enabled entries will be left untouched when trying to renable
     384them:
     385
     386    >>> batch.enable(ac_id)
     387    >>> ac.student_id
     388    'some_user_id'
     389
     390Disabling an entry:
     391
     392    >>> batch.disabled_num
     393    0
     394
     395    >>> ac.disabled
     396    False
     397
     398    >>> batch.disable(ac_id, 'some userid')
     399    >>> ac.disabled
     400    True
     401
     402    >>> ac.student_id
     403    'some userid'
     404
     405    >>> batch.disabled_num
     406    1
     407
     408Already disabled entries will not be disabled again:
     409
     410    >>> batch.disable(ac_id, 'other userid')
     411    >>> ac.student_id
     412    'some userid'
     413
     414Reenabling an entry:
     415
     416    >>> batch.enable(ac_id)
     417    >>> ac.disabled
     418    False
     419
     420    >>> ac.student_id is None
     421    True
     422
     423    >>> ac.invalidation_date is None
     424    True
     425
    290426Access codes get their ``cost`` from the batch they belong to. Note,
    291427that it is advisable to print costs always using a format, as Python
     
    298434    12.12
    299435
     436Searching for serials:
     437
     438    >>> result = batch.search(0, 'serial')
     439    >>> result
     440    [<waeup.sirp...AccessCode object at 0x...>]
     441
     442    >>> result[0].batch_serial
     443    0
     444
     445Searching for AC-IDs:
     446
     447    >>> result = batch.search(ac.representation, 'pin')
     448    >>> result[0].representation
     449    'APP-...-...'
     450
     451Searching for student IDs:
     452
     453    >>> batch.invalidate(ac_id, 'some_new_user_id')
     454    >>> result = batch.search('some_new_user_id', 'stud_id')
     455    >>> result[0].student_id
     456    'some_new_user_id'
     457
     458Searching for not existing entries will return empty lists:
     459
     460    >>> batch.search(12, 'serial')
     461    []
     462
     463    >>> batch.search('not-a-valid-pin', 'pin')
     464    []
     465
     466    >>> batch.search('not-a-student-id', 'stud_id')
     467    []
     468
     469    >>> batch.search('blah', 'not-a-valid-searchtype')
     470    []
    300471
    301472AccessCodeBatchContainer
     
    344515      user ID of the current user.
    345516
     517   .. method:: search(search_term, search_type)
     518
     519      Look in all contained batches for access codes that comply with
     520      the given parameters.
     521
     522      ``search_type`` must be one of ``serial``, ``pin``, or
     523      ``stud_id`` and specifies, what kind of data is contained in the
     524      ``search_term``.
     525
     526      - ``serial`` looks for the AC with the ``serial_batch`` set to
     527        the given (integer) number in ``search_term``. Here
     528        ``search_term`` can be an integer or a string. If it is a
     529        string it will be converted to an int.
     530
     531      - ``pin`` looks for the AC with the ``representation`` set to
     532        the given string in ``search_term``. Here ``search_term`` must
     533        be a string containing the full AC-ID like
     534        ``APP-1-0123456789``.
     535
     536      - ``stud_id`` looks for the AC with the ``student_id`` set to
     537        the given string in ``search_term``. Here ``search_term`` must
     538        be a string containing the full student ID.
     539
     540Examples:
     541---------
     542
     543Creating a batch container:
     544
     545    >>> from waeup.sirp.accesscodes.accesscodes import (
     546    ...   AccessCodeBatchContainer)
     547    >>> container = AccessCodeBatchContainer()
     548
     549Creating batches inside the container:
     550
     551    >>> from datetime import datetime
     552    >>> batch1 = container.createBatch(
     553    ...   datetime.now(), 'some userid', 'FOO', 10.12, 5)
     554
     555    >>> batch2 = container.createBatch(
     556    ...   datetime.now(), 'other userid', 'BAR', 1.95, 5)
     557
     558Searching the container for batch serials:
     559
     560    >>> container.search(1, 'serial')
     561    [<waeup.sirp...AccessCode object at 0x...>,
     562     <waeup.sirp...AccessCode object at 0x...>]
     563
     564    >>> container.search('not-a-number', 'serial')
     565    []
     566
     567    >>> result = container.search('1', 'serial')
     568    >>> result
     569    [<waeup.sirp...AccessCode object at 0x...>,
     570     <waeup.sirp...AccessCode object at 0x...>]
     571
     572Searching for ACs:
     573
     574    >>> ac = result[0]
     575    >>> container.search(ac.representation, 'pin')
     576    [<waeup.sirp...AccessCode object at 0x...>]
     577
     578Searching for student IDs:
     579
     580    >>> ac.__parent__.invalidate(
     581    ...   ac.representation, 'some_user')
     582    >>> container.search('some_user', 'stud_id')
     583    [<waeup.sirp...AccessCode object at 0x...>]
     584
    346585
    347586Access code plugin
Note: See TracChangeset for help on using the changeset viewer.