Changeset 6378 for main


Ignore:
Timestamp:
16 Jun 2011, 15:08:47 (13 years ago)
Author:
uli
Message:

Update accesscode tests: check for exceptions raised when using the
convenience functions invalidate_accesscode() and friends.

Also start to convert tests not to expect access code attributes like
_disabled any more, because we will remove these soon (states will be
handled/set via workflows only).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/tests/test_accesscodes.py

    r6374 r6378  
    2323import tempfile
    2424import unittest
     25from hurry.workflow.interfaces import InvalidTransitionError, IWorkflowState
    2526from zope.app.testing.functional import FunctionalTestCase
    26 from zope.component.hooks import setSite
     27from zope.component.hooks import setSite, clearSite
    2728from waeup.sirp.app import University
    2829from waeup.sirp.testing import FunctionalLayer
    2930from waeup.sirp.accesscodes.accesscodes import (
    3031    AccessCodeBatch, get_access_code, invalidate_accesscode,
    31     disable_accesscode, reenable_accesscode)
     32    disable_accesscode, reenable_accesscode, fire_transition)
     33from waeup.sirp.accesscodes.workflow import INITIALIZED, USED, DISABLED
    3234
    3335class AccessCodeHelpersTests(FunctionalTestCase):
     
    9395        assert result is True
    9496
    95     def test_invalidate_used_accesscode(self):
    96         invalidate_accesscode('APP-1-11111111')
    97         inv_date = self.ac1._invalidation_date
    98         result = invalidate_accesscode('APP-1-11111111')
    99         assert result is False
    100         assert self.ac1._invalidation_date == inv_date
    101 
    102     def test_invalidate_disabled_accesscode(self):
    103         # disabled acs cannot be invalidated.
    104         disable_accesscode('APP-1-11111111')
    105         result = invalidate_accesscode('APP-1-11111111')
    106         assert result is False
    107         assert self.ac1._disabled is True
    108 
    10997    def test_disable_accesscode_unused(self):
     98        # we can disable initialized acs
    11099        assert self.ac1._disabled is False
    111100        disable_accesscode('APP-1-11111111')
     
    113102
    114103    def test_disable_accesscode_used(self):
     104        # we can disable already used acs
    115105        assert self.ac1._disabled is False
    116106        invalidate_accesscode('APP-1-11111111')
     
    119109
    120110    def test_reenable_accesscode(self):
     111        # we can reenable disabled acs
    121112        disable_accesscode('APP-1-11111111')
    122113        result = reenable_accesscode('APP-1-11111111')
     
    124115        assert self.ac1._disabled is False
    125116
    126     def test_reenable_accesscode_enabled(self):
    127         result = reenable_accesscode('APP-1-11111111')
    128         assert result is False
    129         assert self.ac1._disabled is False
     117    def test_fire_transition(self):
     118        # we can fire transitions generally
     119        fire_transition('APP-1-11111111', 'use')
     120        assert IWorkflowState(self.ac1).getState() is USED
     121
     122    def test_fire_transition_toward(self):
     123        # the `toward` keyword is respected
     124        fire_transition('APP-1-11111111', DISABLED, toward=True)
     125        assert IWorkflowState(self.ac1).getState() is DISABLED
     126
     127    def test_fire_transition_no_site(self):
     128        # when no site is available, we will get a TypeError
     129        clearSite()
     130        self.assertRaises(
     131            KeyError,
     132            fire_transition, 'APP-1-11111111', 'use')
     133
     134    def test_fire_transition_broken_ac_id(self):
     135        # if we get an invalid access code id (of wrong format) we get
     136        # ValueErrors
     137        self.assertRaises(
     138            ValueError,
     139            fire_transition, '11111111', 'use')
     140
     141    def test_fire_transition_invalid_batch_id(self):
     142        # if we request a non-existent batch_id, we'll get a KeyError
     143        self.assertRaises(
     144            KeyError,
     145            fire_transition, 'FOO-1-11111111', 'use')
     146
     147    def test_fire_transition_invalid_ac(self):
     148        # if we request a non-exitent access-code, we'll get a KeyError
     149        self.assertRaises(
     150            KeyError,
     151            fire_transition, 'APP-1-NONSENSE', 'use')
     152
     153    def test_fire_transition_undef_trans_id(self):
     154        # asking for undefined transition id means a KeyError
     155        self.assertRaises(
     156            KeyError,
     157            fire_transition, 'APP-1-11111111', 'nonsense')
     158
     159    def test_fire_transition_invalid_transition(self):
     160        # asking for a forbidden transition will result in
     161        # InvalidTransitionError
     162        self.assertRaises(
     163            InvalidTransitionError,
     164            fire_transition, 'APP-1-11111111', 'init') # already initialized
Note: See TracChangeset for help on using the changeset viewer.