Log message for revision 112613:
  Merge string exception removal, coverage from 2.12 branch.

Changed:
  U   Zope/trunk/src/Products/SiteAccess/SiteRoot.py
  U   Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py

-=-
Modified: Zope/trunk/src/Products/SiteAccess/SiteRoot.py
===================================================================
--- Zope/trunk/src/Products/SiteAccess/SiteRoot.py      2010-05-21 13:58:42 UTC 
(rev 112612)
+++ Zope/trunk/src/Products/SiteAccess/SiteRoot.py      2010-05-21 13:58:43 UTC 
(rev 112613)
@@ -62,10 +62,8 @@
                                                   self.priority)
     def _setId(self, id):
         if id != self.id:
-            raise MessageDialog(
-                title='Invalid Id',
-                message='Cannot change the id of a %s' % 
escape(self.meta_type),
-                action ='./manage_main',)
+            raise ValueError('Cannot change the id of a %s'
+                                % escape(self.meta_type))
 
 class SiteRoot(Traverser, Implicit):
     """SiteAccess.SiteRoot object

Modified: Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py
===================================================================
--- Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py    2010-05-21 
13:58:42 UTC (rev 112612)
+++ Zope/trunk/src/Products/SiteAccess/tests/testSiteRoot.py    2010-05-21 
13:58:43 UTC (rev 112613)
@@ -7,6 +7,116 @@
 """
 import unittest
 
+
+class TraverserTests(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from Products.SiteAccess.SiteRoot import Traverser
+        return Traverser
+
+    def _makeOne(self):
+        traverser = self._getTargetClass()()
+        traverser.id = 'testing'
+        return traverser
+
+    def test_addToContainer(self):
+        traverser = self._makeOne()
+        container = DummyContainer()
+        traverser.addToContainer(container)
+        self.failUnless(container.testing is traverser)
+        hook = container.__before_traverse__[(100, 'Traverser')]
+        self.assertEqual(hook.name, 'testing')
+
+    def test_manage_addToContainer_no_nextUrl(self):
+        traverser = self._makeOne()
+        container = DummyContainer()
+        result = traverser.manage_addToContainer(container)
+        self.failUnless(result is None)
+        self.failUnless(container.testing is traverser)
+        hook = container.__before_traverse__[(100, 'Traverser')]
+        self.assertEqual(hook.name, 'testing')
+
+    def test_manage_addToContainer_w_nextUrl_w_name_collision(self):
+        NEXTURL='http://example.com/manage_main'
+        traverser = self._makeOne()
+        container = DummyContainer()
+        container.testing = object()
+        result = traverser.manage_addToContainer(container, nextURL=NEXTURL)
+        self.failUnless(isinstance(result, str))
+        self.failUnless('<TITLE>Item Exists</TITLE>' in result)
+        self.failIf(container.testing is traverser)
+
+    def test_manage_addToContainer_w_nextUrl_wo_name_collision(self):
+        NEXTURL='http://example.com/manage_main'
+        traverser = self._makeOne()
+        container = DummyContainer()
+        result = traverser.manage_addToContainer(container, nextURL=NEXTURL)
+        self.failUnless(isinstance(result, str))
+        self.failUnless('<TITLE>Item Added</TITLE>' in result)
+        self.failUnless(container.testing is traverser)
+        hook = container.__before_traverse__[(100, 'Traverser')]
+        self.assertEqual(hook.name, 'testing')
+
+    def test_manage_beforeDelete_item_is_not_self(self):
+        from ZPublisher.BeforeTraverse import registerBeforeTraverse
+        traverser = self._makeOne()
+        container = DummyContainer()
+        other = container.other = DummyObject(name='other')
+        registerBeforeTraverse(container, other, 'Traverser', 100)
+        item = object()
+        traverser.manage_beforeDelete(item, container)
+        hook = container.__before_traverse__[(100, 'Traverser')]
+        self.assertEqual(hook.name, 'other')
+
+    def test_manage_beforeDelete_item_is_self(self):
+        from ZPublisher.BeforeTraverse import registerBeforeTraverse
+        traverser = self._makeOne()
+        container = DummyContainer()
+        other = container.other = DummyObject(name='other')
+        registerBeforeTraverse(container, other, 'Traverser', 100)
+        traverser.manage_beforeDelete(traverser, container)
+        self.failIf(container.__before_traverse__)
+
+    def test_manage_afterAdd_item_not_self(self):
+        traverser = self._makeOne()
+        container = DummyContainer()
+        item = object()
+        traverser.manage_afterAdd(item, container)
+        self.failIf('__before_traverse__' in container.__dict__)
+
+    def test_manage_afterAdd_item_is_self(self):
+        traverser = self._makeOne()
+        container = DummyContainer()
+        traverser.manage_afterAdd(traverser, container)
+        hook = container.__before_traverse__[(100, 'Traverser')]
+        self.assertEqual(hook.name, 'testing')
+
+    def test__setId_same(self):
+        traverser = self._makeOne()
+        traverser._setId('testing') # doesn't raise
+
+    def test__setId_different(self):
+        traverser = self._makeOne()
+        self.assertRaises(ValueError, traverser._setId, 'other')
+
+
+class DummyObject(object):
+
+    def __init__(self, **kw):
+        self.__dict__.update(kw)
+
+class DummyContainer(object):
+
+    def __init__(self, **kw):
+        self.__dict__.update(kw)
+
+    def _setObject(self, name, object):
+        setattr(self, name, object)
+
+    def this(self):
+        return self
+
+
 class SiteRootRegressions(unittest.TestCase):
 
     def setUp(self):
@@ -39,6 +149,7 @@
                          'http://test_base/test_path')
 
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTest(unittest.makeSuite(SiteRootRegressions))
-    return suite
+    return unittest.TestSuite((
+        unittest.makeSuite(TraverserTests),
+        unittest.makeSuite(SiteRootRegressions),
+    ))

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to