Skip to content

Commit

Permalink
Merge pull request #460 from MITLibraries/bugfix-no-records-error
Browse files Browse the repository at this point in the history
Fix no records bug
  • Loading branch information
hakbailey committed Aug 18, 2022
2 parents 72506a7 + 3d45e54 commit 1b6448f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
7 changes: 3 additions & 4 deletions harvester/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ def harvest(
oai_client = OAIClient(
ctx.obj["HOST"], metadata_format, from_date, until_date, set_spec
)
records = oai_client.retrieve_records(method, exclude_deleted=exclude_deleted)

logger.info("Writing records to output file: %s", ctx.obj["OUTPUT_FILE"])
try:
records = oai_client.retrieve_records(method, exclude_deleted=exclude_deleted)
logger.info("Writing records to output file: %s", ctx.obj["OUTPUT_FILE"])
count = write_records(records, ctx.obj["OUTPUT_FILE"])
except NoRecordsMatch:
logger.error(
logger.info(
"No records harvested: the combination of the provided options results in "
"an empty list."
)
Expand Down
51 changes: 51 additions & 0 deletions tests/fixtures/vcr_cassettes/harvest-list-method-no-records.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
method: GET
uri: https://dspace.mit.edu/oai/request?metadataPrefix=oai_dc&set=com_1721.1_100263&verb=ListRecords
response:
body:
string: !!binary |
H4sIAAAAAAAAA4yRQU/DMAyF/0rke5u0FTBVbRESQiBtMMGQEJcppIZGWpMSG9r9e9IxDrtxs6zv
+fnZ1eXU78Q3BrLe1ZClCgQ641vrPmp43twkC7hsqplKiPc7pA6RBe8HrIFxYjnRDkQX8L0GYs3W
yAOXzv2ofLi6S9arWxEHOKqhYx5KKcdxTP2ATgfT2W+k1IcPGVGZp0rCL1xOZE8EY3HAcqUy+bJa
PpkOe51YF22dwagiW9KhufQmbjIH+o+f+A90zBFjtdBUAWnwjvBaMza5yvNELZLsfJMVZXFW5uq1
kidIFHx+IfF86bcalpb4EY0PLYHokXWrWa/jDe1Ug9d22xoQhFyD8f02u8izNNtmSuXnBTTzthTX
bWnQBtPecortl5RRJ4821V/RVBiCDyI+NP7L+aPpSrPpoLn3op8rJPEeIe5QRFXYV/Kgaqq/1M0P
AAAA//8DAB0k/FonAgAA
headers:
Connection:
- close
Content-Encoding:
- gzip
Content-Type:
- text/xml;charset=UTF-8
Date:
- Tue, 16 Aug 2022 13:35:20 GMT
Set-cookie:
- HttpOnly;Secure
Strict-Transport-Security:
- max-age=63072000
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
27 changes: 25 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def test_harvest_no_options_except_set_spec(caplog, cli_runner, tmp_path):
)


@vcr.use_cassette("tests/fixtures/vcr_cassettes/harvest-no-records.yaml")
def test_harvest_no_records(caplog, cli_runner, tmp_path):
@vcr.use_cassette("tests/fixtures/vcr_cassettes/harvest-get-method-no-records.yaml")
def test_harvest_no_records_get_method(caplog, cli_runner, tmp_path):
with cli_runner.isolated_filesystem(temp_dir=tmp_path):
filepath = tmp_path / "records.xml"
result = cli_runner.invoke(
Expand All @@ -106,6 +106,29 @@ def test_harvest_no_records(caplog, cli_runner, tmp_path):
)


@vcr.use_cassette("tests/fixtures/vcr_cassettes/harvest-list-method-no-records.yaml")
def test_harvest_no_records_list_method(caplog, cli_runner, tmp_path):
with cli_runner.isolated_filesystem(temp_dir=tmp_path):
filepath = tmp_path / "records.xml"
result = cli_runner.invoke(
main,
[
"-h",
"https://dspace.mit.edu/oai/request",
"-o",
filepath,
"harvest",
"-s",
"com_1721.1_100263",
],
)
assert result.exit_code == 0
assert (
"No records harvested: the combination of the provided options results in "
"an empty list." in caplog.text
)


@vcr.use_cassette("tests/fixtures/vcr_cassettes/get-sets.yaml")
def test_setlist(caplog, cli_runner, tmp_path):
with cli_runner.isolated_filesystem(temp_dir=tmp_path):
Expand Down

0 comments on commit 1b6448f

Please sign in to comment.