Changeset 6373


Ignore:
Timestamp:
15 Jun 2011, 23:20:30 (13 years ago)
Author:
uli
Message:

Test new method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py

    r5875 r6373  
    2727import unittest
    2828import doctest
     29from zope.security.testing import Principal, Participation
     30from zope.security.management import newInteraction, endInteraction
    2931from waeup.sirp.utils import helpers
    3032
     
    141143        self.expected += u'test with \xfcmlaut</p>\n</div>'
    142144        return
    143    
     145
    144146    def test_ascii_umlauts(self):
    145147        # Make sure we convert umlauts correctly to unicode.
     
    162164        self.assertTrue(isinstance(helpers.ReST2HTML(source), unicode))
    163165
    164        
     166
    165167class FactoryBaseTestCase(unittest.TestCase):
    166168
     
    172174        self.assertTrue(factory.getInterfaces()(IFakeObject))
    173175        return
    174        
     176
     177class CurrentPrincipalTestCase(unittest.TestCase):
     178
     179    def tearDown(test):
     180        endInteraction() # Just in case, one is still lingering around
     181
     182    def test_existing_principal(self):
     183        # We can get the current principal if one is involved
     184        principal = Principal('myprincipal')
     185        newInteraction(Participation(principal))
     186        result = helpers.get_current_principal()
     187        self.assertTrue(result is principal)
     188
     189    def test_no_participation(self):
     190        # Interactions without participation are handled correctly
     191        newInteraction()
     192        result = helpers.get_current_principal()
     193        self.assertTrue(result is None)
     194
     195    def test_not_existing_principal(self):
     196        # Missing interactions do not raise errors.
     197        result = helpers.get_current_principal()
     198        self.assertTrue(result is None)
     199
    175200def test_suite():
    176201    suite = unittest.TestSuite()
     
    181206        CopyFileSystemTreeTestCase,
    182207        RemoveFileOrDirectoryTestCase,
     208        CurrentPrincipalTestCase,
    183209        ]:
    184210        suite.addTests(
Note: See TracChangeset for help on using the changeset viewer.