[Checkins] SVN: zope.app.intid/trunk/ IntId functionality is moved to zope.intid. Remove it from here.
Dan Korostelev
nadako at gmail.com
Sat Jan 31 15:19:05 EST 2009
Log message for revision 95789:
IntId functionality is moved to zope.intid. Remove it from here.
Changed:
U zope.app.intid/trunk/CHANGES.txt
U zope.app.intid/trunk/buildout.cfg
U zope.app.intid/trunk/setup.py
D zope.app.intid/trunk/src/zope/app/intid/DEPENDENCIES.cfg
D zope.app.intid/trunk/src/zope/app/intid/SETUP.cfg
U zope.app.intid/trunk/src/zope/app/intid/__init__.py
U zope.app.intid/trunk/src/zope/app/intid/browser/configure.zcml
D zope.app.intid/trunk/src/zope/app/intid/browser/ftests.py
A zope.app.intid/trunk/src/zope/app/intid/browser/tests.py
U zope.app.intid/trunk/src/zope/app/intid/browser/tracking.txt
U zope.app.intid/trunk/src/zope/app/intid/configure.zcml
U zope.app.intid/trunk/src/zope/app/intid/ftesting.zcml
U zope.app.intid/trunk/src/zope/app/intid/interfaces.py
U zope.app.intid/trunk/src/zope/app/intid/subscribers.zcml
D zope.app.intid/trunk/src/zope/app/intid/tests.py
D zope.app.intid/trunk/src/zope/app/intid/zope.app.intid-configure.zcml
-=-
Modified: zope.app.intid/trunk/CHANGES.txt
===================================================================
--- zope.app.intid/trunk/CHANGES.txt 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/CHANGES.txt 2009-01-31 20:19:05 UTC (rev 95789)
@@ -2,10 +2,15 @@
CHANGES
=======
-3.6.1 (unreleased)
+3.7.0 (unreleased)
------------------
-- ...
+- Move core functionality to new ``zope.intid`` package, leaving only
+ ZMI-related browser views here.
+
+ Note, that if you used the ``exclude`` directive from ``zc.configuration``
+ package to exclude the ``subscribers.zcml`` file from ``zope.app.intid``,
+ you need to change the directive to exclude it from ``zope.intid`` now.
3.6.0 (2009-01-31)
------------------
Modified: zope.app.intid/trunk/buildout.cfg
===================================================================
--- zope.app.intid/trunk/buildout.cfg 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/buildout.cfg 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,5 +1,5 @@
[buildout]
-develop = .
+develop = . ../zope.intid
parts = test
[test]
Modified: zope.app.intid/trunk/setup.py
===================================================================
--- zope.app.intid/trunk/setup.py 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/setup.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -22,9 +22,9 @@
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
setup(name = 'zope.app.intid',
- version = '3.6.1dev',
+ version = '3.7.0dev',
author='Zope Corporation and Contributors',
- author_email='zope3-dev at zope.org',
+ author_email='zope-dev at zope.org',
description='Integer Id Utility',
long_description=(
read('README.txt')
@@ -42,15 +42,17 @@
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
- url='http://cheeseshop.python.org/pypi/zope.app.intid',
+ url='http://pypi.python.org/pypi/zope.app.intid',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope', 'zope.app'],
- extras_require = dict(test=['zope.app.testing',
+ extras_require = dict(test=['zope.app.authentication',
'zope.app.securitypolicy',
+ 'zope.app.testing',
+ 'zope.app.zcmlfiles',
'zope.site',
- 'zope.app.zcmlfiles']),
+ ]),
install_requires = ['setuptools',
'ZODB3',
'zope.container',
@@ -60,6 +62,7 @@
'zope.interface',
'zope.location',
'zope.security',
+ 'zope.intid',
],
include_package_data = True,
zip_safe = False,
Deleted: zope.app.intid/trunk/src/zope/app/intid/DEPENDENCIES.cfg
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/DEPENDENCIES.cfg 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/DEPENDENCIES.cfg 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1 +0,0 @@
-zope.app.keyreference
Deleted: zope.app.intid/trunk/src/zope/app/intid/SETUP.cfg
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/SETUP.cfg 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/SETUP.cfg 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,3 +0,0 @@
-<data-files zopeskel/etc/package-includes>
- *-configure.zcml
-</data-files>
Modified: zope.app.intid/trunk/src/zope/app/intid/__init__.py
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/__init__.py 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/__init__.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -20,165 +20,11 @@
$Id$
"""
-import random
-import BTrees
-from ZODB.interfaces import IConnection
-from persistent import Persistent
-
-from zope.event import notify
-from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
-from zope.location.interfaces import ILocation
-from zope.component import adapter, getAllUtilitiesRegisteredFor, queryUtility, subscribers
-from zope.component.interfaces import IFactory
-
-from zope.container.interfaces import IObjectRemovedEvent
-from zope.container.interfaces import IObjectAddedEvent
-from zope.container.contained import Contained
-from zope.app.keyreference.interfaces import IKeyReference, NotYet
-
-from zope.app.intid.interfaces import IIntIds, IIntIdEvent
-from zope.app.intid.interfaces import IntIdRemovedEvent
-from zope.app.intid.interfaces import IntIdAddedEvent
-
-
-class IntIds(Persistent, Contained):
- """This utility provides a two way mapping between objects and
- integer ids.
-
- IKeyReferences to objects are stored in the indexes.
- """
- implements(IIntIds)
-
- _v_nextid = None
-
- _randrange = random.randrange
-
- family = BTrees.family32
-
- def __init__(self, family=None):
- if family is not None:
- self.family = family
- self.ids = self.family.OI.BTree()
- self.refs = self.family.IO.BTree()
-
- def __len__(self):
- return len(self.ids)
-
- def items(self):
- return list(self.refs.items())
-
- def __iter__(self):
- return self.refs.iterkeys()
-
- def getObject(self, id):
- return self.refs[id]()
-
- def queryObject(self, id, default=None):
- r = self.refs.get(id)
- if r is not None:
- return r()
- return default
-
- def getId(self, ob):
- try:
- key = IKeyReference(ob)
- except (NotYet, TypeError):
- raise KeyError(ob)
-
- try:
- return self.ids[key]
- except KeyError:
- raise KeyError(ob)
-
- def queryId(self, ob, default=None):
- try:
- return self.getId(ob)
- except KeyError:
- return default
-
- def _generateId(self):
- """Generate an id which is not yet taken.
-
- This tries to allocate sequential ids so they fall into the
- same BTree bucket, and randomizes if it stumbles upon a
- used one.
- """
- while True:
- if self._v_nextid is None:
- self._v_nextid = self._randrange(0, self.family.maxint)
- uid = self._v_nextid
- self._v_nextid += 1
- if uid not in self.refs:
- return uid
- self._v_nextid = None
-
- def register(self, ob):
- # Note that we'll still need to keep this proxy removal.
- ob = removeSecurityProxy(ob)
- key = IKeyReference(ob)
-
- if key in self.ids:
- return self.ids[key]
- uid = self._generateId()
- self.refs[uid] = key
- self.ids[key] = uid
- return uid
-
- def unregister(self, ob):
- # Note that we'll still need to keep this proxy removal.
- ob = removeSecurityProxy(ob)
- key = IKeyReference(ob, None)
- if key is None:
- return
-
- uid = self.ids[key]
- del self.refs[uid]
- del self.ids[key]
-
-
- at adapter(ILocation, IObjectRemovedEvent)
-def removeIntIdSubscriber(ob, event):
- """A subscriber to ObjectRemovedEvent
-
- Removes the unique ids registered for the object in all the unique
- id utilities.
- """
- utilities = tuple(getAllUtilitiesRegisteredFor(IIntIds))
- if utilities:
- key = IKeyReference(ob, None)
- # Register only objects that adapt to key reference
- if key is not None:
- # Notify the catalogs that this object is about to be removed.
- notify(IntIdRemovedEvent(ob, event))
- for utility in utilities:
- try:
- utility.unregister(key)
- except KeyError:
- pass
-
- at adapter(ILocation, IObjectAddedEvent)
-def addIntIdSubscriber(ob, event):
- """A subscriber to ObjectAddedEvent
-
- Registers the object added in all unique id utilities and fires
- an event for the catalogs.
- """
- utilities = tuple(getAllUtilitiesRegisteredFor(IIntIds))
- if utilities: # assert that there are any utilites
- key = IKeyReference(ob, None)
- # Register only objects that adapt to key reference
- if key is not None:
- idmap = {}
- for utility in utilities:
- idmap[utility] = utility.register(key)
- # Notify the catalogs that this object was added.
- notify(IntIdAddedEvent(ob, event, idmap))
-
- at adapter(IIntIdEvent)
-def intIdEventNotify(event):
- """Event subscriber to dispatch IntIdEvent to interested adapters."""
- adapters = subscribers((event.object, event), None)
- for adapter in adapters:
- pass # getting them does the work
+# BBB
+from zope.intid import (
+ IntIds,
+ intIdEventNotify,
+ removeIntIdSubscriber,
+ addIntIdSubscriber
+)
Modified: zope.app.intid/trunk/src/zope/app/intid/browser/configure.zcml
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/browser/configure.zcml 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/browser/configure.zcml 2009-01-31 20:19:05 UTC (rev 95789)
@@ -7,14 +7,14 @@
<addMenuItem
title="Unique Id Utility"
description="A utility that provides unique ids to objects"
- class="zope.app.intid.IntIds"
+ class="zope.intid.IntIds"
permission="zope.ManageSite"
/>
<page
name="index.html"
menu="zmi_views" title="Registered Objects"
- for="zope.app.intid.interfaces.IIntIds"
+ for="zope.intid.interfaces.IIntIds"
permission="zope.ManageServices"
class=".IntIdsView"
template="registrations.pt"
@@ -22,7 +22,7 @@
<page
name="populate"
- for="zope.app.intid.interfaces.IIntIds"
+ for="zope.intid.interfaces.IIntIds"
permission="zope.ManageServices"
class=".IntIdsView"
attribute="populate"
@@ -31,7 +31,7 @@
<icon
name="zmi_icon"
file="intids.png"
- for="zope.app.intid.interfaces.IIntIds"
+ for="zope.intid.interfaces.IIntIds"
/>
</zope:configure>
Deleted: zope.app.intid/trunk/src/zope/app/intid/browser/ftests.py
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/browser/ftests.py 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/browser/ftests.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,29 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Int Id Utility Functional Tests
-
-$Id$
-"""
-import unittest
-from zope.app.testing import functional
-from zope.app.intid.testing import IntIdLayer
-
-def test_suite():
- tracking = functional.FunctionalDocFileSuite('tracking.txt')
- tracking.layer = IntIdLayer
- return unittest.TestSuite((tracking,))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
-
Copied: zope.app.intid/trunk/src/zope/app/intid/browser/tests.py (from rev 95783, zope.app.intid/trunk/src/zope/app/intid/browser/ftests.py)
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/browser/tests.py (rev 0)
+++ zope.app.intid/trunk/src/zope/app/intid/browser/tests.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -0,0 +1,81 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Int Id Utility Functional Tests
+
+$Id$
+"""
+import unittest
+from zope.app.testing import functional
+from zope.app.intid.testing import IntIdLayer
+
+from transaction import commit
+
+from zope.app.testing import setup, ztapi
+from zope.app.testing.functional import BrowserTestCase
+
+from zope.intid import IntIds, intIdEventNotify
+from zope.intid.interfaces import IIntIds
+from zope.traversing.api import traverse
+
+class TestFunctionalIntIds(BrowserTestCase):
+
+ def setUp(self):
+ BrowserTestCase.setUp(self)
+
+ self.basepath = '/++etc++site/default'
+ root = self.getRootFolder()
+
+ sm = traverse(root, '/++etc++site')
+ setup.addUtility(sm, 'intid', IIntIds, IntIds())
+ commit()
+
+ type_name = 'BrowserAdd__zope.intid.IntIds'
+
+ response = self.publish(
+ self.basepath + '/contents.html',
+ basic='mgr:mgrpw',
+ form={'type_name': type_name,
+ 'new_value': 'mgr' })
+
+ def test(self):
+ response = self.publish(self.basepath + '/intid/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEquals(response.getStatus(), 200)
+ # The utility registers in itself when it is being added
+ self.assert_(response.getBody().find('1 objects') > 0)
+ self.assert_('<a href="/++etc++site">/++etc++site</a>'
+ not in response.getBody())
+
+ response = self.publish(self.basepath + '/intid/@@populate',
+ basic='mgr:mgrpw')
+ self.assertEquals(response.getStatus(), 302)
+
+ response = self.publish(self.basepath
+ + '/intid/@@index.html?testing=1',
+ basic='mgr:mgrpw')
+ self.assertEquals(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('3 objects' in body)
+ self.assert_('<a href="/++etc++site">/++etc++site</a>' in body)
+ self.checkForBrokenLinks(body, response.getPath(), basic='mgr:mgrpw')
+
+def test_suite():
+ TestFunctionalIntIds.layer = IntIdLayer
+ browser = unittest.makeSuite(TestFunctionalIntIds)
+ tracking = functional.FunctionalDocFileSuite('tracking.txt')
+ tracking.layer = IntIdLayer
+ return unittest.TestSuite((browser, tracking))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Modified: zope.app.intid/trunk/src/zope/app/intid/browser/tracking.txt
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/browser/tracking.txt 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/browser/tracking.txt 2009-01-31 20:19:05 UTC (rev 95789)
@@ -9,7 +9,7 @@
... Authorization: Basic mgr:mgrpw
... Referer: http://localhost:8081/++etc++site/default/@@contents.html
...
- ... type_name=BrowserAdd__zope.app.intid.IntIds&new_value=""")
+ ... type_name=BrowserAdd__zope.intid.IntIds&new_value=""")
HTTP/1.1 303 ...
...
Location: http://localhost/++etc++site/default/IntIds/@@registration.html
@@ -28,7 +28,7 @@
... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
... Content-Disposition: form-data; name="field.provided"
...
- ... zope.app.intid.interfaces.IIntIds
+ ... zope.intid.interfaces.IIntIds
... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
... Content-Disposition: form-data; name="field.provided-empty-marker"
...
Modified: zope.app.intid/trunk/src/zope/app/intid/configure.zcml
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/configure.zcml 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/configure.zcml 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,37 +1,6 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
- <class class=".IntIds">
- <factory
- id="zope.app.intid.IntIds"
- />
+ <include package="zope.intid" />
+ <include package=".browser" />
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
-
- <require
- permission="zope.Public"
- interface=".interfaces.IIntIdsQuery"
- />
-
- <require
- permission="zope.ManageContent"
- interface=".interfaces.IIntIdsSet"
- />
-
- <require
- permission="zope.Public"
- interface=".interfaces.IIntIdsManage"
- />
-
- </class>
-
- <include file="subscribers.zcml" />
-
- <!-- Views -->
- <include package=".browser" />
-
</configure>
Modified: zope.app.intid/trunk/src/zope/app/intid/ftesting.zcml
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/ftesting.zcml 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/ftesting.zcml 2009-01-31 20:19:05 UTC (rev 95789)
@@ -11,9 +11,8 @@
<include package="zope.app.securitypolicy" />
<include package="zope.app.securitypolicy" file="meta.zcml" />
- <include package="zope.formlib" />
<include package="zope.app.authentication" />
- <include package="zope.app.keyreference" />
+ <include package="zope.keyreference" />
<include package="zope.app.intid" />
<securityPolicy
Modified: zope.app.intid/trunk/src/zope/app/intid/interfaces.py
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/interfaces.py 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/interfaces.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -3,113 +3,16 @@
$Id$
"""
-from zope.interface import Interface, Attribute, implements
-
-class IIntIdsQuery(Interface):
-
- def getObject(uid):
- """Return an object by its unique id"""
-
- def getId(ob):
- """Get a unique id of an object.
- """
-
- def queryObject(uid, default=None):
- """Return an object by its unique id
-
- Return the default if the uid isn't registered
- """
-
- def queryId(ob, default=None):
- """Get a unique id of an object.
-
- Return the default if the object isn't registered
- """
-
- def __iter__():
- """Return an iteration on the ids"""
-
-
-class IIntIdsSet(Interface):
-
- def register(ob):
- """Register an object and returns a unique id generated for it.
-
- The object *must* be adaptable to IKeyReference.
-
- If the object is already registered, its id is returned anyway.
- """
-
- def unregister(ob):
- """Remove the object from the indexes.
-
- KeyError is raised if ob is not registered previously.
- """
-
-class IIntIdsManage(Interface):
- """Some methods used by the view."""
-
- def __len__():
- """Return the number of objects indexed."""
-
- def items():
- """Return a list of (id, object) pairs."""
-
-
-class IIntIds(IIntIdsSet, IIntIdsQuery, IIntIdsManage):
- """A utility that assigns unique ids to objects.
-
- Allows to query object by id and id by object.
- """
-
-
-class IIntIdEvent(Interface):
- """Generic base interface for IntId-related events"""
-
- object = Attribute("The object related to this event")
-
- original_event = Attribute("The ObjectEvent related to this event")
-
-
-class IIntIdRemovedEvent(IIntIdEvent):
- """A unique id will be removed
-
- The event is published before the unique id is removed
- from the utility so that the indexing objects can unindex the object.
- """
-
-
-class IntIdRemovedEvent:
- """The event which is published before the unique id is removed
- from the utility so that the catalogs can unindex the object.
- """
-
- implements(IIntIdRemovedEvent)
-
- def __init__(self, object, event):
- self.object = object
- self.original_event = event
-
-
-class IIntIdAddedEvent(IIntIdEvent):
- """A unique id has been added
-
- The event gets sent when an object is registered in a
- unique id utility.
- """
-
- idmap = Attribute("The dictionary that holds an (utility -> id) mapping of created ids")
-
-
-class IntIdAddedEvent:
- """The event which gets sent when an object is registered in a
- unique id utility.
- """
-
- implements(IIntIdAddedEvent)
-
- def __init__(self, object, event, idmap=None):
- self.object = object
- self.original_event = event
- self.idmap = idmap
+# BBB
+from zope.intid.interfaces import (
+ IIntIdsQuery,
+ IIntIdsSet,
+ IIntIdsManage,
+ IIntIds,
+ IIntIdEvent,
+ IIntIdRemovedEvent,
+ IntIdRemovedEvent,
+ IIntIdAddedEvent,
+ IntIdAddedEvent
+)
Modified: zope.app.intid/trunk/src/zope/app/intid/subscribers.zcml
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/subscribers.zcml 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/subscribers.zcml 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,10 +1,5 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- i18n_domain="zope"
- >
+<configure xmlns="http://namespaces.zope.org/zope">
- <subscriber handler=".removeIntIdSubscriber" />
- <subscriber handler=".addIntIdSubscriber" />
- <subscriber handler=".intIdEventNotify" />
+ <include package="zope.intid" file="subscribers.zcml" />
</configure>
Deleted: zope.app.intid/trunk/src/zope/app/intid/tests.py
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/tests.py 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/tests.py 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1,351 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Tests for the unique id utility.
-
-$Id$
-"""
-import re
-import unittest
-import BTrees
-
-from persistent import Persistent
-from persistent.interfaces import IPersistent
-from transaction import commit
-from ZODB.interfaces import IConnection
-
-from zope.interface import implements
-from zope.interface.verify import verifyObject
-from zope.location.interfaces import ILocation
-
-from zope.component import getSiteManager
-from zope.component.interfaces import IFactory
-
-from zope.traversing.api import traverse
-
-from zope.app.testing import setup, ztapi
-from zope.site.hooks import setSite
-
-from zope.app.intid import IntIds, intIdEventNotify
-from zope.app.intid.interfaces import IIntIds
-from zope.app.intid.testing import IntIdLayer
-from zope.app.keyreference.persistent import KeyReferenceToPersistent
-from zope.app.keyreference.persistent import connectionOfPersistent
-from zope.app.keyreference.interfaces import IKeyReference
-from zope.app.testing.functional import BrowserTestCase
-
-
-class P(Persistent):
- implements(ILocation)
-
-
-class ConnectionStub(object):
- next = 1
-
- def db(self):
- return self
-
- database_name = 'ConnectionStub'
-
- def add(self, ob):
- ob._p_jar = self
- ob._p_oid = self.next
- self.next += 1
-
-
-class ReferenceSetupMixin(object):
- """Registers adapters ILocation->IConnection and IPersistent->IReference"""
- def setUp(self):
- self.root = setup.placefulSetUp(site=True)
- ztapi.provideAdapter(IPersistent, IConnection, connectionOfPersistent)
- ztapi.provideAdapter(IPersistent, IKeyReference,
- KeyReferenceToPersistent)
-
- def tearDown(self):
- setup.placefulTearDown()
-
-
-class TestIntIds(ReferenceSetupMixin, unittest.TestCase):
-
- createIntIds = IntIds
-
- def test_interface(self):
- verifyObject(IIntIds, self.createIntIds())
-
- def test_non_keyreferences(self):
- u = self.createIntIds()
- obj = object()
-
- self.assert_(u.queryId(obj) is None)
- self.assert_(u.unregister(obj) is None)
- self.assertRaises(KeyError, u.getId, obj)
-
- def test(self):
- u = self.createIntIds()
- obj = P()
-
- obj._p_jar = ConnectionStub()
-
- self.assertRaises(KeyError, u.getId, obj)
- self.assertRaises(KeyError, u.getId, P())
-
- self.assert_(u.queryId(obj) is None)
- self.assert_(u.queryId(obj, 42) is 42)
- self.assert_(u.queryId(P(), 42) is 42)
- self.assert_(u.queryObject(42) is None)
- self.assert_(u.queryObject(42, obj) is obj)
-
- uid = u.register(obj)
- self.assert_(u.getObject(uid) is obj)
- self.assert_(u.queryObject(uid) is obj)
- self.assertEquals(u.getId(obj), uid)
- self.assertEquals(u.queryId(obj), uid)
-
- uid2 = u.register(obj)
- self.assertEquals(uid, uid2)
-
- u.unregister(obj)
- self.assertRaises(KeyError, u.getObject, uid)
- self.assertRaises(KeyError, u.getId, obj)
-
- def test_btree_long(self):
- # This is a somewhat arkward test, that *simulates* the border case
- # behaviour of the _generateId method
- u = self.createIntIds()
- u._randrange = lambda x,y:int(2**31-1)
-
- # The chosen int is exactly the largest number possible that is
- # delivered by the randint call in the code
- obj = P()
- obj._p_jar = ConnectionStub()
- uid = u.register(obj)
- self.assertEquals(2**31-1, uid)
- # Make an explicit tuple here to avoid implicit type casts on 2**31-1
- # by the btree code
- self.failUnless(2**31-1 in tuple(u.refs.keys()))
-
- def test_len_items(self):
- u = self.createIntIds()
- obj = P()
- obj._p_jar = ConnectionStub()
-
-
- self.assertEquals(len(u), 0)
- self.assertEquals(u.items(), [])
- self.assertEquals(list(u), [])
-
- uid = u.register(obj)
- ref = KeyReferenceToPersistent(obj)
- self.assertEquals(len(u), 1)
- self.assertEquals(u.items(), [(uid, ref)])
- self.assertEquals(list(u), [uid])
-
- obj2 = P()
- obj2.__parent__ = obj
-
- uid2 = u.register(obj2)
- ref2 = KeyReferenceToPersistent(obj2)
- self.assertEquals(len(u), 2)
- result = u.items()
- expected = [(uid, ref), (uid2, ref2)]
- result.sort()
- expected.sort()
- self.assertEquals(result, expected)
- result = list(u)
- expected = [uid, uid2]
- result.sort()
- expected.sort()
- self.assertEquals(result, expected)
-
- u.unregister(obj)
- u.unregister(obj2)
- self.assertEquals(len(u), 0)
- self.assertEquals(u.items(), [])
-
- def test_getenrateId(self):
- u = self.createIntIds()
- self.assertEquals(u._v_nextid, None)
- id1 = u._generateId()
- self.assert_(u._v_nextid is not None)
- id2 = u._generateId()
- self.assert_(id1 + 1, id2)
- u.refs[id2 + 1] = "Taken"
- id3 = u._generateId()
- self.assertNotEqual(id3, id2 + 1)
- self.assertNotEqual(id3, id2)
- self.assertNotEqual(id3, id1)
-
-
-class TestSubscribers(ReferenceSetupMixin, unittest.TestCase):
-
- def setUp(self):
- from zope.site.folder import Folder, rootFolder
- from zope.component import provideHandler
-
- ReferenceSetupMixin.setUp(self)
-
- sm = getSiteManager(self.root)
- self.utility = setup.addUtility(sm, '1', IIntIds, IntIds())
-
- self.root['folder1'] = Folder()
- self.root._p_jar = ConnectionStub()
- self.root['folder1']['folder1_1'] = self.folder1_1 = Folder()
- self.root['folder1']['folder1_1']['folder1_1_1'] = Folder()
-
- sm1_1 = setup.createSiteManager(self.folder1_1)
- self.utility1 = setup.addUtility(sm1_1, '2', IIntIds, IntIds())
- provideHandler(intIdEventNotify)
-
- def test_removeIntIdSubscriber(self):
- from zope.app.intid import removeIntIdSubscriber
- from zope.container.contained import ObjectRemovedEvent
- from zope.app.intid.interfaces import IIntIdRemovedEvent
- from zope.site.interfaces import IFolder
- parent_folder = self.root['folder1']['folder1_1']
- folder = self.root['folder1']['folder1_1']['folder1_1_1']
- id = self.utility.register(folder)
- id1 = self.utility1.register(folder)
- self.assertEquals(self.utility.getObject(id), folder)
- self.assertEquals(self.utility1.getObject(id1), folder)
- setSite(self.folder1_1)
-
- events = []
- objevents = []
-
- def appendObjectEvent(obj, event):
- objevents.append((obj, event))
-
- ztapi.subscribe([IIntIdRemovedEvent], None, events.append)
- ztapi.subscribe([IFolder, IIntIdRemovedEvent], None, appendObjectEvent)
-
- # This should unregister the object in all utilities, not just the
- # nearest one.
- removeIntIdSubscriber(folder, ObjectRemovedEvent(parent_folder))
-
- self.assertRaises(KeyError, self.utility.getObject, id)
- self.assertRaises(KeyError, self.utility1.getObject, id1)
-
- self.assertEquals(len(events), 1)
- self.assertEquals(events[0].object, folder)
- self.assertEquals(events[0].original_event.object, parent_folder)
-
- self.assertEquals(len(objevents), 1)
- self.assertEquals(objevents[0][0], folder)
- self.assertEquals(objevents[0][1].object, folder)
- self.assertEquals(objevents[0][1].original_event.object, parent_folder)
-
- def test_addIntIdSubscriber(self):
- from zope.app.intid import addIntIdSubscriber
- from zope.container.contained import ObjectAddedEvent
- from zope.app.intid.interfaces import IIntIdAddedEvent
- from zope.site.interfaces import IFolder
- parent_folder = self.root['folder1']['folder1_1']
- folder = self.root['folder1']['folder1_1']['folder1_1_1']
- setSite(self.folder1_1)
-
- events = []
- objevents = []
-
- def appendObjectEvent(obj, event):
- objevents.append((obj, event))
-
- ztapi.subscribe([IIntIdAddedEvent], None, events.append)
- ztapi.subscribe([IFolder, IIntIdAddedEvent], None, appendObjectEvent)
-
- # This should register the object in all utilities, not just the
- # nearest one.
- addIntIdSubscriber(folder, ObjectAddedEvent(parent_folder))
-
- # Check that the folder got registered
- id = self.utility.getId(folder)
- id1 = self.utility1.getId(folder)
-
- self.assertEquals(len(events), 1)
- self.assertEquals(events[0].original_event.object, parent_folder)
- self.assertEquals(events[0].object, folder)
-
- self.assertEquals(len(objevents), 1)
- self.assertEquals(objevents[0][1].original_event.object, parent_folder)
- self.assertEquals(objevents[0][1].object, folder)
- self.assertEquals(objevents[0][0], folder)
-
- idmap = events[0].idmap
- self.assert_(idmap is objevents[0][1].idmap)
- self.assertEquals(len(idmap), 2)
- self.assertEquals(idmap[self.utility], id)
- self.assertEquals(idmap[self.utility1], id1)
-
-class TestIntIds64(TestIntIds):
-
- def createIntIds(self):
- return IntIds(family=BTrees.family64)
-
-
-class TestFunctionalIntIds(BrowserTestCase):
-
- def setUp(self):
- from zope.app.intid import IntIds
- from zope.app.intid.interfaces import IIntIds
-
- BrowserTestCase.setUp(self)
-
- self.basepath = '/++etc++site/default'
- root = self.getRootFolder()
-
- sm = traverse(root, '/++etc++site')
- setup.addUtility(sm, 'intid', IIntIds, IntIds())
- commit()
-
- type_name = 'BrowserAdd__zope.app.intid.IntIds'
-
- response = self.publish(
- self.basepath + '/contents.html',
- basic='mgr:mgrpw',
- form={'type_name': type_name,
- 'new_value': 'mgr' })
-
- def test(self):
- response = self.publish(self.basepath + '/intid/@@index.html',
- basic='mgr:mgrpw')
- self.assertEquals(response.getStatus(), 200)
- # The utility registers in itself when it is being added
- self.assert_(response.getBody().find('1 objects') > 0)
- self.assert_('<a href="/++etc++site">/++etc++site</a>'
- not in response.getBody())
-
- response = self.publish(self.basepath + '/intid/@@populate',
- basic='mgr:mgrpw')
- self.assertEquals(response.getStatus(), 302)
-
- response = self.publish(self.basepath
- + '/intid/@@index.html?testing=1',
- basic='mgr:mgrpw')
- self.assertEquals(response.getStatus(), 200)
- body = response.getBody()
- self.assert_('3 objects' in body)
- self.assert_('<a href="/++etc++site">/++etc++site</a>' in body)
- self.checkForBrokenLinks(body, response.getPath(), basic='mgr:mgrpw')
-
-
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestIntIds))
- suite.addTest(unittest.makeSuite(TestIntIds64))
- suite.addTest(unittest.makeSuite(TestSubscribers))
- # Functional Tests
- TestFunctionalIntIds.layer = IntIdLayer
- suite.addTest(unittest.makeSuite(TestFunctionalIntIds))
- return suite
-
-if __name__ == '__main__':
- unittest.main()
Deleted: zope.app.intid/trunk/src/zope/app/intid/zope.app.intid-configure.zcml
===================================================================
--- zope.app.intid/trunk/src/zope/app/intid/zope.app.intid-configure.zcml 2009-01-31 19:25:35 UTC (rev 95788)
+++ zope.app.intid/trunk/src/zope/app/intid/zope.app.intid-configure.zcml 2009-01-31 20:19:05 UTC (rev 95789)
@@ -1 +0,0 @@
-<include package="zope.app.intid" />
More information about the Checkins
mailing list