Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
fbf16d96
Commit
fbf16d96
authored
May 21, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove string exception.
Coverage for 'Products.SiteAccess.SiteRoot.Traverser'.
parent
85cc5cc8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
7 deletions
+116
-7
src/Products/SiteAccess/SiteRoot.py
src/Products/SiteAccess/SiteRoot.py
+2
-4
src/Products/SiteAccess/tests/testSiteRoot.py
src/Products/SiteAccess/tests/testSiteRoot.py
+114
-3
No files found.
src/Products/SiteAccess/SiteRoot.py
View file @
fbf16d96
...
...
@@ -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
...
...
src/Products/SiteAccess/tests/testSiteRoot.py
View file @
fbf16d96
...
...
@@ -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
),
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment