-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improves overall test coverage to 100%. (closes #21) Signed-off-by: Jan Aage Lavik <jan.age.lavik@cern.ch>
- Loading branch information
Showing
9 changed files
with
326 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,7 @@ | |
import sys | ||
|
||
import mock | ||
|
||
import pkg_resources | ||
|
||
import setuptools | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> | ||
<responseDate>2016-06-02T19:13:02Z</responseDate> | ||
<request verb="ListRecords" until="2015-01-17" from="2015-01-17" metadataPrefix="arXiv" set="physics:hep-lat">http://export.arxiv.org/oai2</request> | ||
<error code="noRecordsMatch"> | ||
No records match the paramaters specified for this selective harvesting request. | ||
</error> | ||
</OAI-PMH> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2014, 2015, 2016 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. | ||
|
||
"""Test for utilities used by OAI harvester.""" | ||
|
||
from __future__ import absolute_import, print_function | ||
|
||
import re | ||
|
||
import responses | ||
from click.testing import CliRunner | ||
|
||
from invenio_oaiharvester.cli import harvest | ||
|
||
|
||
@responses.activate | ||
def test_cli_harvest_idents(script_info, sample_record_xml, tmpdir): | ||
"""Test create user CLI.""" | ||
responses.add( | ||
responses.GET, | ||
'http://export.arxiv.org/oai2', | ||
body=sample_record_xml, | ||
content_type='text/xml' | ||
) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-i', 'oai:arXiv.org:1507.03011'], | ||
obj=script_info | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# Cannot use dates and identifiers | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-f', '2015-01-17', | ||
'-i', 'oai:arXiv.org:1507.03011'], | ||
obj=script_info | ||
) | ||
assert result.exit_code != 0 | ||
|
||
# Queue it | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-i', 'oai:arXiv.org:1507.03011', | ||
'--enqueue'], | ||
obj=script_info | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# Save it directory | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-i', 'oai:arXiv.org:1507.03011', | ||
'-d', tmpdir.dirname], | ||
obj=script_info | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# Missing URL | ||
result = runner.invoke( | ||
harvest, | ||
['-m', 'arXiv', | ||
'-i', 'oai:arXiv.org:1507.03011'], | ||
obj=script_info | ||
) | ||
assert result.exit_code != 0 | ||
|
||
|
||
@responses.activate | ||
def test_cli_harvest_list(script_info, sample_empty_set): | ||
"""Test create user CLI.""" | ||
responses.add( | ||
responses.GET, | ||
re.compile(r'http?://export.arxiv.org/oai2.*set=physics.*'), | ||
body=sample_empty_set, | ||
content_type='text/xml' | ||
) | ||
|
||
runner = CliRunner() | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-s', 'physics', | ||
'-f', '2015-01-17', | ||
'-t', '2015-01-17'], | ||
obj=script_info | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# Queue it | ||
result = runner.invoke( | ||
harvest, | ||
['-u', 'http://export.arxiv.org/oai2', | ||
'-m', 'arXiv', | ||
'-s', 'physics', | ||
'-f', '2015-01-17', | ||
'-t', '2015-01-17', | ||
'--enqueue'], | ||
obj=script_info | ||
) | ||
assert result.exit_code == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of Invenio. | ||
# Copyright (C) 2016 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. | ||
|
||
import re | ||
|
||
import pytest | ||
import responses | ||
|
||
from invenio_oaiharvester.errors import InvenioOAIHarvesterError | ||
from invenio_oaiharvester.signals import oaiharvest_finished | ||
from invenio_oaiharvester.tasks import get_specific_records, \ | ||
list_records_from_dates | ||
|
||
|
||
@responses.activate | ||
def test_get_specific_records(app, sample_record_xml): | ||
"""Test that getting records via identifiers work with prefix.""" | ||
def foo(request, records, name): | ||
assert len(records) == 1 | ||
|
||
responses.add( | ||
responses.GET, | ||
'http://export.arxiv.org/oai2', | ||
body=sample_record_xml, | ||
content_type='text/xml' | ||
) | ||
oaiharvest_finished.connect(foo) | ||
try: | ||
with app.app_context(): | ||
get_specific_records( | ||
'oai:arXiv.org:1507.03011', | ||
metadata_prefix="arXiv", | ||
url='http://export.arxiv.org/oai2' | ||
) | ||
# As a list of identifiers | ||
get_specific_records( | ||
['oai:arXiv.org:1507.03011'], | ||
metadata_prefix="arXiv", | ||
url='http://export.arxiv.org/oai2' | ||
) | ||
finally: | ||
oaiharvest_finished.disconnect(foo) | ||
|
||
|
||
@responses.activate | ||
def test_list_records_from_dates(app, sample_list_xml): | ||
"""Check harvesting of records from multiple setspecs.""" | ||
def bar(request, records, name): | ||
assert len(records) == 150 | ||
|
||
responses.add( | ||
responses.GET, | ||
re.compile(r'http?://export.arxiv.org/oai2.*set=physics.*'), | ||
body=sample_list_xml, | ||
content_type='text/xml' | ||
) | ||
oaiharvest_finished.connect(bar) | ||
try: | ||
with app.app_context(): | ||
list_records_from_dates( | ||
metadata_prefix='arXiv', | ||
from_date='2015-01-15', | ||
until_date='2015-01-20', | ||
url='http://export.arxiv.org/oai2', | ||
name=None, | ||
setspecs='physics' | ||
) | ||
finally: | ||
oaiharvest_finished.disconnect(bar) |
Oops, something went wrong.