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
b3dcf745
Commit
b3dcf745
authored
May 21, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for 'Products.SiteAccess.AccessRule.manage_addAccessRule'.
parent
15c8dbc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
120 additions
and
0 deletions
+120
-0
src/Products/SiteAccess/tests/testAccessRule.py
src/Products/SiteAccess/tests/testAccessRule.py
+120
-0
No files found.
src/Products/SiteAccess/tests/testAccessRule.py
View file @
b3dcf745
...
...
@@ -63,18 +63,138 @@ class AccessRuleTests(unittest.TestCase):
self
.
assertEqual
(
request
.
_virtual_root
,
None
)
class
Test_manage_addAccessRule
(
unittest
.
TestCase
):
def
_callFUT
(
self
,
container
,
method_id
,
REQUEST
):
from
Products.SiteAccess.AccessRule
import
manage_addAccessRule
return
manage_addAccessRule
(
container
,
method_id
,
REQUEST
)
def
test_no_method_id_no_existing_rules_no_request
(
self
):
container
=
DummyContainer
()
result
=
self
.
_callFUT
(
container
,
None
,
None
)
self
.
failUnless
(
result
is
None
)
self
.
failIf
(
container
.
__dict__
)
def
test_no_method_id_no_existing_rules_w_request
(
self
):
container
=
DummyContainer
()
result
=
self
.
_callFUT
(
container
,
None
,
{
'URL1'
:
'http://example.com/'
})
self
.
failUnless
(
isinstance
(
result
,
str
))
self
.
failUnless
(
'<TITLE>No Access Rule</TITLE>'
in
result
)
self
.
failIf
(
container
.
__dict__
)
def
test_no_method_id_w_existing_rules_no_request
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
result
=
self
.
_callFUT
(
container
,
None
,
None
)
self
.
failUnless
(
result
is
None
)
self
.
failIf
(
container
.
__before_traverse__
)
self
.
failIf
(
'icon'
in
old_rule
.
__dict__
)
def
test_w_method_id_w_existing_rules_w_request_none
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
request
=
DummyRequest
(
URL1
=
'http://example.com/'
)
request
.
form
=
{
'none'
:
'1'
}
result
=
self
.
_callFUT
(
container
,
None
,
request
)
self
.
failUnless
(
isinstance
(
result
,
str
))
self
.
failUnless
(
'<TITLE>No Access Rule</TITLE>'
in
result
)
self
.
failIf
(
container
.
__before_traverse__
)
self
.
failIf
(
'icon'
in
old_rule
.
__dict__
)
def
test_w_invalid_method_id_w_existing_rules_no_request
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
result
=
self
.
_callFUT
(
container
,
'nonesuch'
,
None
)
self
.
failUnless
(
result
is
None
)
self
.
failUnless
((
99
,
'AccessRule'
)
in
container
.
__before_traverse__
)
rule
=
container
.
__before_traverse__
[(
99
,
'AccessRule'
)]
self
.
assertEqual
(
rule
.
name
,
'old_rule'
)
self
.
assertEqual
(
old_rule
.
icon
,
'rule_icon.jpg'
)
def
test_w_invalid_method_id_w_existing_rules_w_request
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
request
=
DummyRequest
(
URL1
=
'http://example.com/'
)
request
.
form
=
{}
result
=
self
.
_callFUT
(
container
,
'nonesuch'
,
request
)
self
.
failUnless
(
isinstance
(
result
,
str
))
self
.
failUnless
(
'<TITLE>Invalid Method Id</TITLE>'
in
result
)
self
.
failUnless
((
99
,
'AccessRule'
)
in
container
.
__before_traverse__
)
rule
=
container
.
__before_traverse__
[(
99
,
'AccessRule'
)]
self
.
assertEqual
(
rule
.
name
,
'old_rule'
)
self
.
assertEqual
(
old_rule
.
icon
,
'rule_icon.jpg'
)
def
test_w_valid_method_id_w_existing_rules_no_request
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
new_rule
=
container
.
new_rule
=
DummyObject
(
name
=
'new_rule'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
result
=
self
.
_callFUT
(
container
,
'new_rule'
,
None
)
self
.
failUnless
(
result
is
None
)
self
.
failIf
((
99
,
'AccessRule'
)
in
container
.
__before_traverse__
)
self
.
failUnless
((
1
,
'AccessRule'
)
in
container
.
__before_traverse__
)
rule
=
container
.
__before_traverse__
[(
1
,
'AccessRule'
)]
self
.
assertEqual
(
rule
.
name
,
'new_rule'
)
self
.
failIf
(
'icon'
in
old_rule
.
__dict__
)
self
.
assertEqual
(
new_rule
.
icon
,
'misc_/SiteAccess/AccessRule.gif'
)
def
test_w_valid_method_id_w_existing_rules_w_request
(
self
):
from
ZPublisher.BeforeTraverse
import
registerBeforeTraverse
container
=
DummyContainer
()
old_rule
=
container
.
old_rule
=
DummyObject
(
name
=
'old_rule'
,
icon
=
'rule_icon.jpg'
)
new_rule
=
container
.
new_rule
=
DummyObject
(
name
=
'new_rule'
)
registerBeforeTraverse
(
container
,
old_rule
,
'AccessRule'
)
request
=
DummyRequest
(
URL1
=
'http://example.com/'
)
request
.
form
=
{}
result
=
self
.
_callFUT
(
container
,
'new_rule'
,
request
)
self
.
failUnless
(
isinstance
(
result
,
str
))
self
.
failUnless
(
'<TITLE>Access Rule Set</TITLE>'
in
result
)
self
.
failIf
((
99
,
'AccessRule'
)
in
container
.
__before_traverse__
)
self
.
failUnless
((
1
,
'AccessRule'
)
in
container
.
__before_traverse__
)
rule
=
container
.
__before_traverse__
[(
1
,
'AccessRule'
)]
self
.
assertEqual
(
rule
.
name
,
'new_rule'
)
self
.
failIf
(
'icon'
in
old_rule
.
__dict__
)
self
.
assertEqual
(
new_rule
.
icon
,
'misc_/SiteAccess/AccessRule.gif'
)
class
DummyRequest
(
dict
):
_virtual_root
=
None
def
setVirtualRoot
(
self
,
root
):
self
.
_virtual_root
=
root
class
DummyObject
(
object
):
def
__init__
(
self
,
**
kw
):
self
.
__dict__
.
update
(
kw
)
class
DummyContainer
(
object
):
def
__init__
(
self
,
**
kw
):
self
.
__dict__
.
update
(
kw
)
def
this
(
self
):
return
self
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
AccessRuleTests
),
unittest
.
makeSuite
(
Test_manage_addAccessRule
),
))
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