Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
CMFUid.tests.test_uidhandling.UniqueIdHandlerTests Class Reference
Inheritance diagram for CMFUid.tests.test_uidhandling.UniqueIdHandlerTests:
Inheritance graph
[legend]
Collaboration diagram for CMFUid.tests.test_uidhandling.UniqueIdHandlerTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def test_z3interfaces
def test_getUidOfNotYetRegisteredObject
def test_getInvalidUid
def test_getUidOfRegisteredObject
def test_getRegisteredObjectByUid
def test_getUnregisteredObject
def test_getUidOfUnregisteredObject
def test_reregisterObject
def test_unregisterObjectWithoutUid
def test_setNewUidByHandWithCheck
def test_setSameUidOnSameObjectWithCheck
def test_setExistingUidOnDifferentObjectWithCheckRaisesException
def test_setExistingUidOnDifferentObjectWithoutCheck
def test_setNoneAsUidRaisesException
def test_setArbitraryKindOfUidRaisesException
def test_UidCataloging
def test_UidCatalogingDoesNotAcquireUid

Private Member Functions

def _getTargetClass

Detailed Description

Definition at line 38 of file test_uidhandling.py.


Member Function Documentation

Definition at line 40 of file test_uidhandling.py.

00040 
00041     def _getTargetClass(self):
00042         from Products.CMFUid.UniqueIdHandlerTool import UniqueIdHandlerTool
00043 
00044         return UniqueIdHandlerTool

Definition at line 45 of file test_uidhandling.py.

00045 
00046     def setUp(self):
00047         from Products.CMFCore.CatalogTool import CatalogTool
00048         from Products.CMFUid.UniqueIdAnnotationTool \
00049                 import UniqueIdAnnotationTool
00050         from Products.CMFUid.UniqueIdGeneratorTool \
00051                 import UniqueIdGeneratorTool
00052         SecurityTest.setUp(self)
00053         self.root._setObject('portal_catalog', CatalogTool())
00054         self.root._setObject('portal_uidgenerator', UniqueIdGeneratorTool())
00055         self.root._setObject('portal_uidannotation', UniqueIdAnnotationTool())
00056         self.root._setObject('portal_uidhandler', self._getTargetClass()())
00057         self.root._setObject('dummy', DummyContent(id='dummy'))
00058         self.root._setObject('dummy2', DummyContent(id='dummy2'))
00059 
00060         sm = getSiteManager()
00061         sm.registerUtility( self.root.portal_uidannotation
00062                           , IUniqueIdAnnotationManagement
00063                           )
00064         sm.registerUtility(self.root.portal_uidgenerator, IUniqueIdGenerator)

Definition at line 65 of file test_uidhandling.py.

00065 
00066     def tearDown(self):
00067         cleanUp()
00068         SecurityTest.tearDown(self)

Here is the call graph for this function:

Definition at line 87 of file test_uidhandling.py.

00087 
00088     def test_getInvalidUid(self):
00089         handler = self.root.portal_uidhandler
00090         dummy = self.root.dummy
00091         UniqueIdError = handler.UniqueIdError
00092 
00093         self.assertEqual(handler.queryObject(100, None), None)
00094         self.assertRaises(UniqueIdError, handler.getObject, 100)
00095         self.assertEqual(handler.unrestrictedQueryObject(100, None), None)
00096         self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, 100)
00097 
00098         uid = handler.register(dummy)
00099         self.assertEqual(handler.queryObject(uid+1, None), None)
00100         self.assertRaises(UniqueIdError, handler.getObject, uid+1)
00101         self.assertEqual(handler.unrestrictedQueryObject(uid+1, None), None)
00102         self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, uid+1)

Definition at line 110 of file test_uidhandling.py.

00110 
00111     def test_getRegisteredObjectByUid(self):
00112         handler = self.root.portal_uidhandler
00113         dummy = self.root.dummy
00114 
00115         uid = handler.register(dummy)
00116         self.assertEqual(handler.getObject(uid), dummy)
00117         self.assertEqual(handler.unrestrictedGetObject(uid), dummy)

Definition at line 79 of file test_uidhandling.py.

00079 
00080     def test_getUidOfNotYetRegisteredObject(self):
00081         handler = self.root.portal_uidhandler
00082         dummy = self.root.dummy
00083         UniqueIdError = handler.UniqueIdError
00084 
00085         self.assertEqual(handler.queryUid(dummy, None), None)
00086         self.assertRaises(UniqueIdError, handler.getUid, dummy)

Definition at line 103 of file test_uidhandling.py.

00103 
00104     def test_getUidOfRegisteredObject(self):
00105         handler = self.root.portal_uidhandler
00106         dummy = self.root.dummy
00107 
00108         uid = handler.register(dummy)
00109         self.assertEqual(handler.getUid(dummy), uid)

Definition at line 130 of file test_uidhandling.py.

00130 
00131     def test_getUidOfUnregisteredObject(self):
00132         handler = self.root.portal_uidhandler
00133         dummy = self.root.dummy
00134         UniqueIdError = handler.UniqueIdError
00135 
00136         uid = handler.register(dummy)
00137         handler.unregister(dummy)
00138         self.assertEqual(handler.queryUid(dummy, None), None)
00139         self.assertRaises(UniqueIdError, handler.getUid, dummy)

Definition at line 118 of file test_uidhandling.py.

00118 
00119     def test_getUnregisteredObject(self):
00120         handler = self.root.portal_uidhandler
00121         dummy = self.root.dummy
00122         UniqueIdError = handler.UniqueIdError
00123 
00124         uid = handler.register(dummy)
00125         handler.unregister(dummy)
00126         self.assertEqual(handler.queryObject(uid, None), None)
00127         self.assertRaises(UniqueIdError, handler.getObject, uid)
00128         self.assertEqual(handler.unrestrictedQueryObject(uid, None), None)
00129         self.assertRaises(UniqueIdError, handler.unrestrictedGetObject, uid)

Definition at line 140 of file test_uidhandling.py.

00140 
00141     def test_reregisterObject(self):
00142         handler = self.root.portal_uidhandler
00143         dummy = self.root.dummy
00144 
00145         uid1_reg = handler.register(dummy)
00146         uid1_get = handler.getUid(dummy)
00147         uid2_reg = handler.register(dummy)
00148         uid2_get = handler.getUid(dummy)
00149         self.assertEqual(uid1_reg, uid2_reg)
00150         self.assertEqual(uid1_get, uid2_get)
00151         self.assertEqual(uid1_reg, uid1_get)

Definition at line 227 of file test_uidhandling.py.

00227 
00228     def test_setArbitraryKindOfUidRaisesException(self):
00229         handler = self.root.portal_uidhandler
00230         dummy = self.root.dummy
00231         UniqueIdError = handler.UniqueIdError
00232 
00233         uid = handler.register(dummy)
00234 
00235         # As we don't know what kind of exception the implementation
00236         # throws lets check for all exceptions!
00237         # IMHO it makes sense here to catch exceptions in general here!
00238         self.assertRaises(Exception, handler.setUid, dummy, DummyUid())

Definition at line 184 of file test_uidhandling.py.

00184 
00185     def test_setExistingUidOnDifferentObjectWithCheckRaisesException(self):
00186         handler = self.root.portal_uidhandler
00187         dummy = self.root.dummy
00188         dummy2 = self.root.dummy2
00189         UniqueIdError = handler.UniqueIdError
00190 
00191         # registering and unregisterung a object just to get a free uid
00192         uid1_reg = handler.register(dummy)
00193         uid2_reg = handler.register(dummy2)
00194 
00195         self.assertRaises(UniqueIdError, handler.setUid, dummy2, uid1_reg)

Definition at line 196 of file test_uidhandling.py.

00196 
00197     def test_setExistingUidOnDifferentObjectWithoutCheck(self):
00198         handler = self.root.portal_uidhandler
00199         dummy = self.root.dummy
00200         dummy2 = self.root.dummy2
00201         UniqueIdError = handler.UniqueIdError
00202 
00203         # registering and unregisterung a object just to get a free uid
00204         uid1_reg = handler.register(dummy)
00205         uid2_reg = handler.register(dummy2)
00206 
00207         # now lets double the unique id
00208         handler.setUid(dummy2, uid1_reg, check_uniqueness=False)
00209 
00210         # calling a getter returns one object and generates a log
00211         # we can't capture. So let's ask the catalog directly.
00212         catalog = self.root.portal_catalog
00213         result = catalog({handler.UID_ATTRIBUTE_NAME: uid1_reg})
00214         self.assertEqual(len(result), 2)
00215 
00216         # dummy2 shall not be reachable anymore by uid2_reg
00217         self.assertRaises(UniqueIdError, handler.getBrain, uid2_reg)

Definition at line 159 of file test_uidhandling.py.

00159 
00160     def test_setNewUidByHandWithCheck(self):
00161         handler = self.root.portal_uidhandler
00162         dummy = self.root.dummy
00163 
00164         # registering and unregisterung a object just to get a free uid
00165         unused_uid = handler.register(dummy)
00166         handler.unregister(dummy)
00167 
00168         handler.setUid(dummy, unused_uid)
00169 
00170         result = handler.getUid(dummy)
00171         self.assertEqual(unused_uid, result)

Definition at line 218 of file test_uidhandling.py.

00218 
00219     def test_setNoneAsUidRaisesException(self):
00220         handler = self.root.portal_uidhandler
00221         dummy = self.root.dummy
00222         UniqueIdError = handler.UniqueIdError
00223 
00224         uid = handler.register(dummy)
00225 
00226         self.assertRaises(UniqueIdError, handler.setUid, dummy, None)

Definition at line 172 of file test_uidhandling.py.

00172 
00173     def test_setSameUidOnSameObjectWithCheck(self):
00174         handler = self.root.portal_uidhandler
00175         dummy = self.root.dummy
00176 
00177         uid = handler.register(dummy)
00178 
00179         # just setting the same uid another time is allowed
00180         handler.setUid(dummy, uid)
00181 
00182         result = handler.getUid(dummy)
00183         self.assertEqual(uid, result)

Definition at line 239 of file test_uidhandling.py.

00239 
00240     def test_UidCataloging(self):
00241         handler = self.root.portal_uidhandler
00242         catalog = self.root.portal_catalog
00243         dummy = self.root.dummy
00244 
00245         uid = handler.register(dummy)
00246         brains = catalog(cmf_uid=uid)
00247         self.assertEqual(len(brains), 1)

Definition at line 248 of file test_uidhandling.py.

00248 
00249     def test_UidCatalogingDoesNotAcquireUid(self):
00250         handler = self.root.portal_uidhandler
00251         catalog = self.root.portal_catalog
00252         self.root._setObject('folder', DummyFolder('folder'))
00253         folder = self.root.folder
00254 
00255         uid = handler.register(folder)
00256         brains = catalog(cmf_uid=uid)
00257         self.assertEqual(len(brains), 1)
00258 
00259         # Now catalog an unregistered subobject of the folder.
00260         # It should not acquire the cmf_uid, obviously.
00261         folder._setObject('dummy', DummyContent(id='dummy'))
00262         folder.dummy.indexObject()
00263         brains = catalog(cmf_uid=uid)
00264         self.assertEqual(len(brains), 1)
00265 

Definition at line 152 of file test_uidhandling.py.

00152 
00153     def test_unregisterObjectWithoutUid(self):
00154         handler = self.root.portal_uidhandler
00155         dummy = self.root.dummy
00156         UniqueIdError = handler.UniqueIdError
00157 
00158         self.assertRaises(UniqueIdError, handler.unregister, dummy)

Definition at line 69 of file test_uidhandling.py.

00069 
00070     def test_z3interfaces(self):
00071         from zope.interface.verify import verifyClass
00072         from Products.CMFUid.interfaces import IUniqueIdBrainQuery
00073         from Products.CMFUid.interfaces import IUniqueIdHandler
00074         from Products.CMFUid.interfaces import IUniqueIdUnrestrictedQuery
00075 
00076         verifyClass(IUniqueIdBrainQuery, self._getTargetClass())
00077         verifyClass(IUniqueIdHandler, self._getTargetClass())
00078         verifyClass(IUniqueIdUnrestrictedQuery, self._getTargetClass())


The documentation for this class was generated from the following file: