-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to consolidate testing based on discussion in #6
* Move fixtures to conftest.py * Merge crossref and wiley mockers * Add integration test in test_awd.py
- Loading branch information
Showing
5 changed files
with
71 additions
and
40 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
|
||
import pytest | ||
import requests_mock | ||
|
||
|
||
@pytest.fixture() | ||
def web_mock(work_record): | ||
with requests_mock.Mocker() as m: | ||
pdf = b"Test content" | ||
request_headers = { | ||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " | ||
"(KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" | ||
} | ||
m.get( | ||
"http://example.com/doi/10.1002/term.3131", | ||
text="Forbidden", | ||
status_code=403, | ||
) | ||
m.get( | ||
"http://example.com/doi/10.1002/term.3131", | ||
content=pdf, | ||
request_headers=request_headers, | ||
) | ||
m.get( | ||
"http://example.com/works/10.1002/term.3131?mailto=dspace-lib@mit.edu", | ||
json=work_record, | ||
) | ||
yield m | ||
|
||
|
||
@pytest.fixture() | ||
def work_record(): | ||
return json.loads(open("fixtures/crossref.json", "r").read()) |
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,32 @@ | ||
from awd import crossref, wiley | ||
|
||
|
||
def test_awd(web_mock): | ||
dois = crossref.get_dois_from_spreadsheet("fixtures/test.xlsx") | ||
for doi in dois: | ||
work = crossref.get_crossref_work_from_doi("http://example.com/works/", doi) | ||
value_dict = crossref.get_metadata_dict_from_crossref_work(work) | ||
pdf = wiley.get_wiley_pdf("http://example.com/doi/", doi) | ||
# value_dict transformed into DSpace metadata | ||
# DSpace metadata and pdf sent to DSpace submission service | ||
assert pdf == b"Test content" | ||
assert value_dict["publisher"] == "Wiley" | ||
assert value_dict["author"] == [ | ||
"Eivazzadeh‐Keihan, Reza", | ||
"Bahojb Noruzi, Ehsan", | ||
"Khanmohammadi Chenab, Karim", | ||
"Jafari, Amir", | ||
"Radinekiyan, Fateme", | ||
"Hashemi, Seyed Masoud", | ||
"Ahmadpour, Farnoush", | ||
"Behboudi, Ali", | ||
"Mosafer, Jafar", | ||
"Mokhtarzadeh, Ahad", | ||
"Maleki, Ali", | ||
"Hamblin, Michael R.", | ||
] | ||
assert value_dict["URL"] == "http://dx.doi.org/10.1002/term.3131" | ||
assert value_dict["container-title"] == [ | ||
"Journal of Tissue Engineering and Regenerative Medicine" | ||
] | ||
assert value_dict["issued"] == "2020-09-30" |
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 |
---|---|---|
@@ -1,21 +1,7 @@ | ||
import pytest | ||
import requests_mock | ||
|
||
from awd import wiley | ||
|
||
|
||
@pytest.fixture() | ||
def wiley_mock(): | ||
with requests_mock.Mocker() as m: | ||
pdf = b"Test content" | ||
m.get( | ||
"http://example.com/doi/10.1002/term.3131", | ||
content=pdf, | ||
) | ||
yield m | ||
|
||
|
||
def test_get_crossref_work_from_dois(wiley_mock): | ||
def test_get_crossref_work_from_dois(web_mock): | ||
doi = "10.1002/term.3131" | ||
pdf = wiley.get_wiley_pdf("http://example.com/doi/", doi) | ||
assert pdf == b"Test content" |