summaryrefslogtreecommitdiff
path: root/src/zope/traversing
diff options
context:
space:
mode:
authorStephan Richter <srichter@cipherhealth.com>2013-02-21 01:30:05 -0500
committerStephan Richter <srichter@cipherhealth.com>2013-02-21 01:30:05 -0500
commit40228e587ab01a73b99ef01568a11a357b7a72fb (patch)
treedd4aeb85ad333cd88faa9cbaf27791ded63d1131 /src/zope/traversing
parent02ead7794791f2dabbdbad08d484936d05a8508e (diff)
downloadzope-traversing-40228e587ab01a73b99ef01568a11a357b7a72fb.tar.gz
Removed zope.container dependency and cleaned up everything for a next
release. All tox tests pass.
Diffstat (limited to 'src/zope/traversing')
-rw-r--r--src/zope/traversing/browser/tests.py4
-rw-r--r--src/zope/traversing/testing.py35
-rw-r--r--src/zope/traversing/tests/ftesting.zcml1
-rw-r--r--src/zope/traversing/tests/test_conveniencefunctions.py5
-rw-r--r--src/zope/traversing/tests/test_traverser.py4
-rw-r--r--src/zope/traversing/tests/test_vhosting.py40
6 files changed, 68 insertions, 21 deletions
diff --git a/src/zope/traversing/browser/tests.py b/src/zope/traversing/browser/tests.py
index 1688ea2..6eab7b1 100644
--- a/src/zope/traversing/browser/tests.py
+++ b/src/zope/traversing/browser/tests.py
@@ -29,7 +29,7 @@ from zope.publisher.http import IHTTPRequest, HTTPCharsets
from zope.location.interfaces import ILocation
from zope.location.location import LocationProxy
-from zope.container.contained import contained
+from zope.traversing.testing import contained, Contained
class IRoot(Interface):
@@ -37,7 +37,7 @@ class IRoot(Interface):
@implementer(IRoot)
-class Root(object):
+class Root(Contained):
pass
diff --git a/src/zope/traversing/testing.py b/src/zope/traversing/testing.py
index 84db062..e10ea6b 100644
--- a/src/zope/traversing/testing.py
+++ b/src/zope/traversing/testing.py
@@ -20,7 +20,7 @@ import zope.interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.location.traversing \
import LocationPhysicallyLocatable, RootPhysicallyLocatable
-from zope.location.interfaces import ILocationInfo, IRoot
+from zope.location.interfaces import IContained, ILocationInfo, IRoot
from zope.traversing.interfaces import ITraversable, ITraverser
from zope.traversing.adapters import DefaultTraversable
from zope.traversing.adapters import Traverser
@@ -28,6 +28,39 @@ from zope.traversing.browser import SiteAbsoluteURL, AbsoluteURL
from zope.traversing.browser.interfaces import IAbsoluteURL
from zope.traversing.namespace import etc
+@zope.interface.implementer(IContained)
+class Contained(object):
+ __parent__ = None
+ __name__ = None
+
+@zope.interface.implementer(IContained)
+class ContainedProxy(object):
+ __parent__ = None
+ __name__ = None
+ __obj__ = None
+
+ def __init__(self, obj):
+ self.__obj__ = obj
+
+ def __getattr__(self, name):
+ return getattr(self.__obj__, name)
+
+ def __setattr__(self, name, value):
+ if name in ['__parent__', '__name__', '__obj__']:
+ self.__dict__[name] = value
+ return
+ setattr(self.__obj__, name, value)
+
+ def __eq__(self, value):
+ return self.__obj__ == value
+
+
+def contained(obj, root, name=None):
+ if not IContained.providedBy(obj):
+ obj = ContainedProxy(obj)
+ obj.__parent__ = root
+ obj.__name__ = name
+ return obj
# BBB: Kept for backward-compatibility, in case some package depends on it.
def setUp(): #pragma: nocover
diff --git a/src/zope/traversing/tests/ftesting.zcml b/src/zope/traversing/tests/ftesting.zcml
index 139a1e5..d9e6edc 100644
--- a/src/zope/traversing/tests/ftesting.zcml
+++ b/src/zope/traversing/tests/ftesting.zcml
@@ -9,7 +9,6 @@
<include package="zope.security" file="meta.zcml" />
<include package="zope.browserresource" />
- <include package="zope.container" />
<include package="zope.location" />
<include package="zope.publisher" />
<include package="zope.traversing" />
diff --git a/src/zope/traversing/tests/test_conveniencefunctions.py b/src/zope/traversing/tests/test_conveniencefunctions.py
index 9a71697..72c1861 100644
--- a/src/zope/traversing/tests/test_conveniencefunctions.py
+++ b/src/zope/traversing/tests/test_conveniencefunctions.py
@@ -23,11 +23,10 @@ from zope.location.traversing \
from zope.location.interfaces import ILocationInfo, IRoot, LocationError
from zope.security.proxy import Proxy
from zope.security.checker import selectChecker
+
from zope.traversing.adapters import Traverser, DefaultTraversable
from zope.traversing.interfaces import ITraversable, ITraverser
-
-from zope.container.contained import contained
-
+from zope.traversing.testing import contained, Contained
class C(object):
__parent__ = None
diff --git a/src/zope/traversing/tests/test_traverser.py b/src/zope/traversing/tests/test_traverser.py
index f4a5eb6..42d2ceb 100644
--- a/src/zope/traversing/tests/test_traverser.py
+++ b/src/zope/traversing/tests/test_traverser.py
@@ -30,9 +30,7 @@ from zope.security.management import newInteraction, endInteraction
from zope.traversing.adapters import Traverser, DefaultTraversable
from zope.traversing.interfaces import ITraversable, ITraverser
-
-from zope.container.contained import Contained, contained
-
+from zope.traversing.testing import contained, Contained
class ParticipationStub(object):
diff --git a/src/zope/traversing/tests/test_vhosting.py b/src/zope/traversing/tests/test_vhosting.py
index 4a3af97..be61ba7 100644
--- a/src/zope/traversing/tests/test_vhosting.py
+++ b/src/zope/traversing/tests/test_vhosting.py
@@ -14,22 +14,26 @@
"""Functional tests for virtual hosting.
"""
import os
+import transaction
import unittest
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
-import transaction
+try:
+ from UserDict import UserDict
+except ImportError:
+ from collections import UserDict
+import zope.component
import zope.interface
from zope.browserresource.resource import Resource
from zope.configuration import xmlconfig
-from zope.container import btree
-from zope.container.contained import Contained
-from zope.container.interfaces import IContainer
from zope.location.interfaces import IRoot
from zope.publisher.browser import BrowserRequest, BrowserView
+from zope.publisher.interfaces import NotFound
+from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.publish import publish
from zope.publisher.skinnable import setDefaultSkin
from zope.security.checker import defineChecker, NamesChecker, NoProxy
@@ -40,20 +44,32 @@ from zope.testing.cleanup import cleanUp
from zope.traversing.adapters import traversePathElement
from zope.traversing.api import traverse
-from zope.traversing.testing import browserResource
+from zope.traversing.testing import browserResource, Contained, contained
class MyObj(Contained):
def __getitem__(self, key):
return traverse(self, '/foo/bar/' + key)
-
-class IFolder(IContainer):
+class IFolder(zope.interface.Interface):
pass
-@zope.interface.implementer(IFolder)
-class Folder(btree.BTreeContainer):
- pass
+@zope.interface.implementer(IFolder, IBrowserPublisher)
+class Folder(Contained, UserDict):
+ def __init__(self):
+ UserDict.__init__(self, {})
+
+ def __setitem__(self, name, value):
+ value.__parent__ = self
+ value.__name__ = name
+ UserDict.__setitem__(self, name, value)
+
+ def publishTraverse(self, request, name):
+ subob = self.get(name, None)
+ if subob is None:
+ raise NotFound(self.context, name, request)
+ return subob
+
@zope.interface.implementer(IRoot)
class RootFolder(Folder):
@@ -142,6 +158,8 @@ class TestVirtualHosting(unittest.TestCase):
def tearDown(self):
undefineChecker(MyObj)
+ undefineChecker(RootFolder)
+ undefineChecker(Folder)
cleanUp()
def makeRequest(self, path=''):
@@ -253,7 +271,7 @@ class TestVirtualHosting(unittest.TestCase):
def verify(self, path, content):
result = self.publish(path)
self.assertEquals(result.getStatus(), 200)
- self.assertEquals(result.consumeBody(), content)
+ self.assertEquals(result.consumeBody().decode(), content)
def verifyRedirect(self, path, location):
result = self.publish(path)