Back to index

plone3  3.1.7
case.py
Go to the documentation of this file.
00001 from unittest import TestCase
00002 from zope.component import getGlobalSiteManager
00003 from zope.interface import implements
00004 from plone.keyring.interfaces import IKeyManager
00005 from AccessControl.SecurityManagement import newSecurityManager
00006 from AccessControl.SecurityManagement import noSecurityManager
00007 from AccessControl.User import User
00008 
00009 
00010 class MockKeyManager:
00011     implements(IKeyManager)
00012 
00013     keys = [ "one", "two", "three", "four", "five" ]
00014 
00015     def secret(self):
00016         return self.keys[0]
00017 
00018     def __getitem__(self, key):
00019         return self.keys
00020 
00021 
00022 class KeyringTestCase(TestCase):
00023     def setUp(self):
00024         self.sm=getGlobalSiteManager()
00025         self.manager=MockKeyManager()
00026         self.sm.registerUtility(self.manager, provided=IKeyManager, event=False)
00027         # Tests modify the user object so we better make sure it is *our*
00028         # user object and not the built-in Anonymous User.
00029         newSecurityManager(None, User('dummy', 'secret', (), ()))
00030 
00031     def tearDown(self):
00032         self.sm.unregisterUtility(self.manager, provided=IKeyManager)
00033         noSecurityManager()
00034