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
21c4e9e6
Commit
21c4e9e6
authored
Aug 01, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for CatalogSearchArgumentsMap and implement __contains__
parent
85691f65
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
3 deletions
+62
-3
src/Products/ZCatalog/Catalog.py
src/Products/ZCatalog/Catalog.py
+6
-3
src/Products/ZCatalog/tests/test_catalog.py
src/Products/ZCatalog/tests/test_catalog.py
+56
-0
No files found.
src/Products/ZCatalog/Catalog.py
View file @
21c4e9e6
...
...
@@ -815,7 +815,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
return
CatalogReport
(
self
,
query
,
threshold
)
class
CatalogSearchArgumentsMap
:
class
CatalogSearchArgumentsMap
(
object
)
:
"""Multimap catalog arguments coming simultaneously from keywords
and request.
...
...
@@ -850,9 +850,12 @@ class CatalogSearchArgumentsMap:
try
:
self
[
key
]
except
KeyError
:
return
0
return
False
else
:
return
1
return
True
def
__contains__
(
self
,
name
):
return
self
.
has_key
(
name
)
def
mergeResults
(
results
,
has_sort_keys
,
reverse
):
...
...
src/Products/ZCatalog/tests/test_catalog.py
View file @
21c4e9e6
...
...
@@ -428,6 +428,61 @@ class TestRangeSearch(CatalogBase, unittest.TestCase):
"%d vs [%d,%d]"
%
(
r
.
number
,
m
,
n
))
class
TestCatalogSearchArgumentsMap
(
unittest
.
TestCase
):
def
_makeOne
(
self
,
request
=
None
,
keywords
=
None
):
from
Products.ZCatalog.Catalog
import
CatalogSearchArgumentsMap
return
CatalogSearchArgumentsMap
(
request
,
keywords
)
def
test_init_empty
(
self
):
argmap
=
self
.
_makeOne
()
self
.
assert_
(
argmap
)
def
test_init_request
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
foo
=
'bar'
),
None
)
self
.
assertEquals
(
argmap
.
get
(
'foo'
),
'bar'
)
def
test_init_keywords
(
self
):
argmap
=
self
.
_makeOne
(
None
,
dict
(
foo
=
'bar'
))
self
.
assertEquals
(
argmap
.
get
(
'foo'
),
'bar'
)
def
test_getitem
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
'a'
),
dict
(
b
=
'b'
))
self
.
assertEquals
(
argmap
[
'a'
],
'a'
)
self
.
assertEquals
(
argmap
[
'b'
],
'b'
)
self
.
assertRaises
(
KeyError
,
argmap
.
__getitem__
,
'c'
)
def
test_getitem_emptystring
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
''
,
c
=
'c'
),
dict
(
b
=
''
,
c
=
''
))
self
.
assertRaises
(
KeyError
,
argmap
.
__getitem__
,
'a'
)
self
.
assertRaises
(
KeyError
,
argmap
.
__getitem__
,
'b'
)
self
.
assertEquals
(
argmap
[
'c'
],
'c'
)
def
test_get
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
'a'
),
dict
(
b
=
'b'
))
self
.
assertEquals
(
argmap
.
get
(
'a'
),
'a'
)
self
.
assertEquals
(
argmap
.
get
(
'b'
),
'b'
)
self
.
assertEquals
(
argmap
.
get
(
'c'
),
None
)
self
.
assertEquals
(
argmap
.
get
(
'c'
,
'default'
),
'default'
)
def
test_keywords_precedence
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
'a'
,
c
=
'r'
),
dict
(
b
=
'b'
,
c
=
'k'
))
self
.
assertEquals
(
argmap
.
get
(
'c'
),
'k'
)
self
.
assertEquals
(
argmap
[
'c'
],
'k'
)
def
test_haskey
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
'a'
),
dict
(
b
=
'b'
))
self
.
assert_
(
argmap
.
has_key
(
'a'
))
self
.
assert_
(
argmap
.
has_key
(
'b'
))
self
.
assert_
(
not
argmap
.
has_key
(
'c'
))
def
test_contains
(
self
):
argmap
=
self
.
_makeOne
(
dict
(
a
=
'a'
),
dict
(
b
=
'b'
))
self
.
assert_
(
'a'
in
argmap
)
self
.
assert_
(
'b'
in
argmap
)
self
.
assert_
(
'c'
not
in
argmap
)
class
TestMerge
(
CatalogBase
,
unittest
.
TestCase
):
# Test merging results from multiple catalogs
...
...
@@ -523,5 +578,6 @@ def test_suite():
suite
.
addTest
(
unittest
.
makeSuite
(
TestAddDelIndexes
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestCatalogObject
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestRangeSearch
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestCatalogSearchArgumentsMap
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestMerge
))
return
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