Commit f1115b27 authored by Tres Seaver's avatar Tres Seaver

Merge string exception removal, coverage from 2.12 branch.

parent a09d23fc
......@@ -62,10 +62,8 @@ class Traverser(Persistent, Item):
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
......
......@@ -7,6 +7,116 @@ See http://www.zope.org/Collectors/Zope/2077
"""
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 @@ class SiteRootRegressions(unittest.TestCase):
'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),
))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment