Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79680319
oai_repository_unit_tests.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
Tue, Aug 27, 17:25
Size
5 KB
Mime Type
text/x-python
Expires
Thu, Aug 29, 17:25 (2 d)
Engine
blob
Format
Raw Data
Handle
20214039
Attached To
R3600 invenio-infoscience
oai_repository_unit_tests.py
View Options
# -*- coding: utf-8 -*-
## Invenio OAI repository unit tests.
##
## This file is part of Invenio.
## Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 oai repository."""
__revision__
=
"$Id$"
from
invenio.testutils
import
InvenioTestCase
import
re
from
cStringIO
import
StringIO
from
invenio
import
oai_repository_server
from
invenio.testutils
import
make_test_suite
,
run_test_suite
class
TestVerbs
(
InvenioTestCase
):
"""Test for OAI verb functionality."""
def
test_verbs
(
self
):
"""oairepository - testing verbs"""
self
.
assertNotEqual
(
None
,
re
.
search
(
"Identify"
,
oai_repository_server
.
oai_identify
({
'verb'
:
'Identify'
})))
ret
=
StringIO
()
oai_repository_server
.
oai_list_records_or_identifiers
(
ret
,
{
'verb'
:
'ListIdentifiers'
,
'metadataPrefix'
:
'marcxml'
})
self
.
assertNotEqual
(
None
,
re
.
search
(
"ListIdentifiers"
,
ret
.
getvalue
()))
ret
=
StringIO
()
oai_repository_server
.
oai_list_records_or_identifiers
(
ret
,
{
'verb'
:
'ListRecords'
,
'metadataPrefix'
:
'marcxml'
})
self
.
assertNotEqual
(
None
,
re
.
search
(
"ListRecords"
,
ret
.
getvalue
()))
self
.
assertNotEqual
(
None
,
re
.
search
(
"ListMetadataFormats"
,
oai_repository_server
.
oai_list_metadata_formats
({
'verb'
:
'ListMetadataFormats'
})))
self
.
assertNotEqual
(
None
,
re
.
search
(
"ListSets"
,
oai_repository_server
.
oai_list_sets
({
'verb'
:
'ListSets'
})))
self
.
assertNotEqual
(
None
,
re
.
search
(
"GetRecord"
,
oai_repository_server
.
oai_get_record
({
'identifier'
:
'oai:atlantis.cern.ch:1'
,
'verb'
:
'GetRecord'
})))
class
TestErrorCodes
(
InvenioTestCase
):
"""Test for handling OAI error codes."""
def
test_issue_error_identify
(
self
):
"""oairepository - testing error codes"""
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"IllegalVerb"
})
if
code
==
'badVerb'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"Identify"
,
'test'
:
"test"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListIdentifiers"
,
'metadataPrefix'
:
"oai_dc"
,
'from'
:
"some_random_date"
,
'until'
:
"some_random_date"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListIdentifiers"
,
'metadataPrefix'
:
"oai_dc"
,
'from'
:
"2001-01-01"
,
'until'
:
"2002-01-01T00:00:00Z"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListIdentifiers"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListIdentifiers"
,
'metadataPrefix'
:
"illegal_mdp"
})
if
code
==
'cannotDisseminateFormat'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListIdentifiers"
,
'metadataPrefix'
:
"oai_dc"
,
'metadataPrefix'
:
"oai_dc"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListRecords"
,
'metadataPrefix'
:
"oai_dc"
,
'set'
:
"really_wrong_set"
,
'from'
:
"some_random_date"
,
'until'
:
"some_random_date"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
"ListRecords"
})
if
code
==
'badArgument'
])
self
.
assertNotEqual
([],
[
code
for
(
code
,
dummy_text
)
in
oai_repository_server
.
check_argd
({
'verb'
:
'ListRecords'
,
'resumptionToken'
:
''
})
if
code
==
'badResumptionToken'
])
TEST_SUITE
=
make_test_suite
(
TestVerbs
,
TestErrorCodes
)
if
__name__
==
"__main__"
:
run_test_suite
(
TEST_SUITE
)
Event Timeline
Log In to Comment