Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92218514
test_utils_solr.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 18, 11:03
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Nov 20, 11:03 (2 d)
Engine
blob
Format
Raw Data
Handle
22388579
Attached To
R3600 invenio-infoscience
test_utils_solr.py
View Options
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2008, 2009, 2010, 2011, 2013 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Unit tests for the solrutils library."""
from
invenio.base.wrappers
import
lazy_import
from
invenio.testsuite
import
make_test_suite
,
run_test_suite
,
InvenioTestCase
replace_invalid_solr_characters
=
lazy_import
(
'invenio.legacy.miscutil.solrutils_bibindex_indexer:'
'replace_invalid_solr_characters'
)
get_collection_filter
=
lazy_import
(
'invenio.legacy.miscutil.solrutils_bibrank_searcher:'
'get_collection_filter'
)
class
TestReplaceInvalidCharacters
(
InvenioTestCase
):
"""Test for removal of invalid Solr characters and control characters."""
def
test_no_replacement
(
self
):
"""solrutils - no characters to replace"""
utext_in
=
unicode
(
'foo
\n
bar
\t
fab
\n\r
'
,
'utf-8'
)
utext_out
=
unicode
(
'foo
\n
bar
\t
fab
\n\r
'
,
'utf-8'
)
self
.
assertEqual
(
utext_out
,
replace_invalid_solr_characters
(
utext_in
))
def
test_replace_control_characters
(
self
):
"""solrutils - replacement of control characters"""
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u0000\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u0003\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u0008\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u000B\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u000C\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u000E\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u0012\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\u001F\n
de'
))
def
test_replace_invalid_chars
(
self
):
"""solrutils - replacement of invalid characters"""
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\uD800\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\uDF12\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\uDFFF\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\uFFFE\n
de'
))
self
.
assertEqual
(
u'abc
\n
de'
,
replace_invalid_solr_characters
(
u'abc
\uFFFF\n
de'
))
class
TestSolrRankingHelpers
(
InvenioTestCase
):
"""Test for Solr ranking helper functions."""
def
test_get_collection_filter
(
self
):
"""solrutils - creation of collection filter"""
import
intbitset
self
.
assertEqual
(
''
,
get_collection_filter
(
intbitset
.
intbitset
([]),
0
))
self
.
assertEqual
(
''
,
get_collection_filter
(
intbitset
.
intbitset
([]),
1
))
self
.
assertEqual
(
''
,
get_collection_filter
(
intbitset
.
intbitset
([
1
,
2
,
3
,
4
,
5
]),
0
))
self
.
assertEqual
(
'id:(5)'
,
get_collection_filter
(
intbitset
.
intbitset
([
1
,
2
,
3
,
4
,
5
]),
1
))
self
.
assertEqual
(
'id:(4 5)'
,
get_collection_filter
(
intbitset
.
intbitset
([
1
,
2
,
3
,
4
,
5
]),
2
))
self
.
assertEqual
(
'id:(1 2 3 4 5)'
,
get_collection_filter
(
intbitset
.
intbitset
([
1
,
2
,
3
,
4
,
5
]),
5
))
self
.
assertEqual
(
'id:(1 2 3 4 5)'
,
get_collection_filter
(
intbitset
.
intbitset
([
1
,
2
,
3
,
4
,
5
]),
6
))
TEST_SUITE
=
make_test_suite
(
TestReplaceInvalidCharacters
,
TestSolrRankingHelpers
)
if
__name__
==
"__main__"
:
run_test_suite
(
TEST_SUITE
)
Event Timeline
Log In to Comment