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
6077a3ad
Commit
6077a3ad
authored
Mar 23, 2004
by
Casey Duncan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add catalog brain tests to head
parent
f21091fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
0 deletions
+141
-0
lib/python/Products/ZCatalog/tests/testBrains.py
lib/python/Products/ZCatalog/tests/testBrains.py
+141
-0
No files found.
lib/python/Products/ZCatalog/tests/testBrains.py
0 → 100644
View file @
6077a3ad
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Unittests for Catalog brains
$Id: testBrains.py,v 1.2 2004/03/23 21:27:03 caseman Exp $"""
import
unittest
import
Acquisition
from
zExceptions
import
Unauthorized
from
ZODB.POSException
import
ConflictError
class
Happy
(
Acquisition
.
Implicit
):
"""Happy content"""
def
__init__
(
self
,
id
):
self
.
id
=
id
class
Secret
(
Happy
):
"""Object that raises Unauthorized when accessed"""
def
__of__
(
self
,
parent
):
raise
Unauthorized
class
Conflicter
(
Happy
):
"""Object that raises ConflictError when accessed"""
def
__of__
(
self
,
parent
):
raise
ConflictError
class
DummyRequest
(
Acquisition
.
Implicit
):
def
physicalPathToURL
(
self
,
path
,
relative
=
False
):
if
not
relative
:
path
=
'http://superbad.com'
+
path
return
path
_marker
=
object
()
class
DummyCatalog
(
Acquisition
.
Implicit
):
_objs
=
{
'/happy'
:
Happy
(
'happy'
),
'/secret'
:
Secret
(
'secret'
),
'/conflicter'
:
Conflicter
(
'conflicter'
)}
_paths
=
_objs
.
keys
()
+
[
'/zonked'
]
_paths
.
sort
()
def
restrictedTraverse
(
self
,
path
,
default
=
_marker
):
try
:
return
self
.
_objs
[
path
].
__of__
(
self
)
except
(
KeyError
,
Unauthorized
):
if
default
is
not
_marker
:
return
default
raise
def
getpath
(
self
,
rid
):
return
self
.
_paths
[
rid
]
def
getobject
(
self
,
rid
):
return
self
.
restrictedTraverse
(
self
.
_paths
[
rid
])
def
resolve_url
(
self
,
path
,
REQUEST
):
path
=
path
[
path
.
find
(
'/'
,
path
.
find
(
'//'
)
+
1
):]
# strip server part
return
self
.
restrictedTraverse
(
path
)
class
ConflictingCatalog
(
DummyCatalog
):
def
getpath
(
self
,
rid
):
raise
ConflictError
class
TestBrains
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
cat
=
DummyCatalog
()
self
.
cat
.
REQUEST
=
DummyRequest
()
def
makeBrain
(
self
,
rid
):
from
Products.ZCatalog.CatalogBrains
import
AbstractCatalogBrain
class
Brain
(
AbstractCatalogBrain
):
__record_schema__
=
{
'test_field'
:
0
,
'data_record_id_'
:
1
}
return
Brain
((
'test'
,
rid
)).
__of__
(
self
.
cat
)
def
testHasKey
(
self
):
b
=
self
.
makeBrain
(
1
)
self
.
failUnless
(
b
.
has_key
(
'test_field'
))
self
.
failUnless
(
b
.
has_key
(
'data_record_id_'
))
self
.
failIf
(
b
.
has_key
(
'godel'
))
def
testGetPath
(
self
):
b
=
[
self
.
makeBrain
(
rid
)
for
rid
in
range
(
3
)]
self
.
assertEqual
(
b
[
0
].
getPath
(),
'/conflicter'
)
self
.
assertEqual
(
b
[
1
].
getPath
(),
'/happy'
)
self
.
assertEqual
(
b
[
2
].
getPath
(),
'/secret'
)
def
testGetPathPropagatesConflictErrors
(
self
):
self
.
cat
=
ConflictingCatalog
()
b
=
self
.
makeBrain
(
0
)
self
.
assertRaises
(
ConflictError
,
b
.
getPath
)
def
testGetURL
(
self
):
b
=
self
.
makeBrain
(
0
)
self
.
assertEqual
(
b
.
getURL
(),
'http://superbad.com/conflicter'
)
def
testGetRID
(
self
):
b
=
self
.
makeBrain
(
42
)
self
.
assertEqual
(
b
.
getRID
(),
42
)
def
testGetObjectHappy
(
self
):
b
=
self
.
makeBrain
(
1
)
self
.
assertEqual
(
b
.
getPath
(),
'/happy'
)
self
.
failUnless
(
b
.
getObject
().
aq_base
is
self
.
cat
.
getobject
(
1
).
aq_base
)
def
testGetObjectPropagatesConflictErrors
(
self
):
b
=
self
.
makeBrain
(
0
)
self
.
assertEqual
(
b
.
getPath
(),
'/conflicter'
)
self
.
assertRaises
(
ConflictError
,
b
.
getObject
)
def
testGetObjectReturnsNoneForUnauthorized
(
self
):
b
=
self
.
makeBrain
(
2
)
self
.
assertEqual
(
b
.
getPath
(),
'/secret'
)
self
.
assertEqual
(
b
.
getObject
(),
None
)
def
testGetObjectReturnsNoneForMissing
(
self
):
b
=
self
.
makeBrain
(
3
)
self
.
assertEqual
(
b
.
getPath
(),
'/zonked'
)
self
.
assertRaises
(
KeyError
,
self
.
cat
.
getobject
,
3
)
self
.
assertEqual
(
b
.
getObject
(),
None
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestBrains
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
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