Skip to content

Commit

Permalink
#84 add additional tests ua_string
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Dec 13, 2019
1 parent d8c16f8 commit 0790a4e
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
40 changes: 38 additions & 2 deletions test/test-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
vcr_path = 'test/vcr_cassettes/setting_ua_string.yaml'
@vcr.use_cassette(vcr_path)
def test_ua_string():
"settings (ua_string) - with ua string"
"settings (ua_string) - with ua string, works"
res = cr_with_ua.works(ids = '10.1371/journal.pone.0033693')
x = open(vcr_path, "r").read()
xy = yaml.safe_load(x)
Expand All @@ -24,7 +24,7 @@ def test_ua_string():
vcr_noua_path = 'test/vcr_cassettes/setting_no_ua_string.yaml'
@vcr.use_cassette(vcr_noua_path)
def test_no_ua_string():
"settings (ua_string) - without ua string"
"settings (ua_string) - without ua string, works"
res = cr_without_ua.works(ids = '10.1371/journal.pone.0033693')
x = open(vcr_noua_path, "r").read()
xy = yaml.safe_load(x)
Expand All @@ -33,6 +33,42 @@ def test_no_ua_string():
assert 'foo bar' not in heads['User-Agent'][0]
assert 'foo bar' not in heads['X-USER-AGENT'][0]

vcr_path_members = 'test/vcr_cassettes/setting_ua_string_members.yaml'
@vcr.use_cassette(vcr_path_members)
def test_ua_string_members():
"settings (ua_string) - with ua string, members"
res = cr_with_ua.members(query = "ecology", limit = 2)
x = open(vcr_path_members, "r").read()
xy = yaml.safe_load(x)
heads = xy['interactions'][0]['request']['headers']

assert 'foo bar' in heads['User-Agent'][0]
assert 'foo bar' in heads['X-USER-AGENT'][0]

vcr_path_prefixes = 'test/vcr_cassettes/setting_ua_string_prefixes.yaml'
@vcr.use_cassette(vcr_path_prefixes)
def test_ua_string_prefixes():
"settings (ua_string) - with ua string, prefixes"
res = cr_with_ua.prefixes(ids = "10.1016", works = True, sample = 2)
x = open(vcr_path_prefixes, "r").read()
xy = yaml.safe_load(x)
heads = xy['interactions'][0]['request']['headers']

assert 'foo bar' in heads['User-Agent'][0]
assert 'foo bar' in heads['X-USER-AGENT'][0]

vcr_path_registration_agency = 'test/vcr_cassettes/setting_ua_string_registration_agency.yaml'
@vcr.use_cassette(vcr_path_registration_agency)
def test_ua_string_registration_agency():
"settings (ua_string) - with ua string, registration_agency"
res = cr_with_ua.registration_agency(u'10.1126/science.169.3946.635')
x = open(vcr_path_registration_agency, "r").read()
xy = yaml.safe_load(x)
heads = xy['interactions'][0]['request']['headers']

assert 'foo bar' in heads['User-Agent'][0]
assert 'foo bar' in heads['X-USER-AGENT'][0]

@raises(TypeError)
def test_ua_string_errors():
"settings (ua_string) - fails well"
Expand Down
34 changes: 34 additions & 0 deletions test/vcr_cassettes/setting_ua_string_members.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.22.0 habanero/0.7.2 foo bar]
X-USER-AGENT: [python-requests/2.22.0 habanero/0.7.2 foo bar]
method: GET
uri: https://api.crossref.org/members?query=ecology&rows=2
response:
body: {string: '{"status":"ok","message-type":"member-list","message-version":"1.0.0","message":{"items-per-page":2,"query":{"start-index":0,"search-terms":"ecology"},"total-results":21,"items":[{"last-status-check-time":1576109829876,"primary-name":"Japanese
Society of Microbial Ecology","counts":{"total-dois":1255,"current-dois":180,"backfile-dois":1075},"breakdowns":{"dois-by-issued-year":[[2012,82],[2013,67],[2014,66],[2016,65],[2018,64],[2017,59],[2019,57],[2009,54],[2008,54],[2011,52],[2015,50],[2010,49],[2007,47],[2004,41],[1999,41],[1998,38],[2001,36],[2005,32],[2003,31],[2006,30],[2002,30],[2000,28],[1993,28],[1997,22],[1994,19],[1995,18],[1989,16],[1996,15],[1991,15],[1992,11],[1990,11],[1988,11],[1987,10],[1986,6]]},"prefixes":["10.1264"],"coverage":{"affiliations-current":1.0,"similarity-checking-current":1.0,"funders-backfile":0.0,"licenses-backfile":0.0,"funders-current":0.0,"affiliations-backfile":0.13767442107200623,"resource-links-backfile":0.0,"orcids-backfile":0.0,"update-policies-current":0.0,"open-references-backfile":0.0,"orcids-current":0.0,"similarity-checking-backfile":0.11348836869001389,"references-backfile":0.7218604683876038,"award-numbers-backfile":0.0,"update-policies-backfile":0.0,"licenses-current":0.0,"award-numbers-current":0.0,"abstracts-backfile":0.0,"resource-links-current":0.0,"abstracts-current":0.0,"open-references-current":0.0,"references-current":0.9055555462837219},"prefix":[{"value":"10.1264","name":"Japanese
Society of Microbial Ecology","public-references":false,"reference-visibility":"limited"}],"id":336,"tokens":["japanese","society","of","microbial","ecology"],"counts-type":{"all":{"journal-article":1255},"current":{"journal-article":180},"backfile":{"journal-article":1075}},"coverage-type":{"all":{"journal-article":{"last-status-check-time":1576109820255,"affiliations":0.26135459542274475,"abstracts":0.0,"orcids":0.0,"licenses":0.0,"references":0.748207151889801,"funders":0.0,"similarity-checking":0.24063745141029358,"award-numbers":0.0,"update-policies":0.0,"resource-links":0.0,"open-references":0.0}},"backfile":{"journal-article":{"last-status-check-time":1576109817085,"affiliations":0.13767442107200623,"abstracts":0.0,"orcids":0.0,"licenses":0.0,"references":0.7218604683876038,"funders":0.0,"similarity-checking":0.11348836869001389,"award-numbers":0.0,"update-policies":0.0,"resource-links":0.0,"open-references":0.0}},"current":{"journal-article":{"last-status-check-time":1576109814770,"affiliations":1.0,"abstracts":0.0,"orcids":0.0,"licenses":0.0,"references":0.9055555462837219,"funders":0.0,"similarity-checking":1.0,"award-numbers":0.0,"update-policies":0.0,"resource-links":0.0,"open-references":0.0}}},"flags":{"deposits-abstracts-current":false,"deposits-orcids-current":false,"deposits":true,"deposits-affiliations-backfile":true,"deposits-update-policies-backfile":false,"deposits-similarity-checking-backfile":true,"deposits-award-numbers-current":false,"deposits-resource-links-current":false,"deposits-articles":true,"deposits-affiliations-current":true,"deposits-funders-current":false,"deposits-references-backfile":true,"deposits-abstracts-backfile":false,"deposits-licenses-backfile":false,"deposits-award-numbers-backfile":false,"deposits-open-references-backfile":false,"deposits-open-references-current":false,"deposits-references-current":true,"deposits-resource-links-backfile":false,"deposits-orcids-backfile":false,"deposits-funders-backfile":false,"deposits-update-policies-current":false,"deposits-similarity-checking-current":true,"deposits-licenses-current":false},"location":"5-3
Yonbancho Chiyoda-ku Tokyo 102-0081 Japan","names":["Japanese Society of Microbial
Ecology"]},{"last-status-check-time":1576120343715,"primary-name":"Journal
of Vector Ecology","counts":{"total-dois":27,"current-dois":0,"backfile-dois":27},"breakdowns":{"dois-by-issued-year":[[2014,27]]},"prefixes":["10.3376"],"coverage":{"affiliations-current":0,"similarity-checking-current":0,"funders-backfile":0.0,"licenses-backfile":0.0,"funders-current":0,"affiliations-backfile":0.0,"resource-links-backfile":0.0,"orcids-backfile":0.0,"update-policies-current":0,"open-references-backfile":0.0,"orcids-current":0,"similarity-checking-backfile":0.0,"references-backfile":0.0,"award-numbers-backfile":0.0,"update-policies-backfile":0.0,"licenses-current":0,"award-numbers-current":0,"abstracts-backfile":0.0,"resource-links-current":0,"abstracts-current":0,"open-references-current":0,"references-current":0},"prefix":[{"value":"10.3376","name":"BioOne
(Journal of Vector Ecology)","public-references":false,"reference-visibility":"limited"}],"id":1950,"tokens":["journal","of","vector","ecology"],"counts-type":{"all":{"journal-article":27},"current":{},"backfile":{"journal-article":27}},"coverage-type":{"all":{"journal-article":{"last-status-check-time":1576120335991,"affiliations":0.0,"abstracts":0.0,"orcids":0.0,"licenses":0.0,"references":0.0,"funders":0.0,"similarity-checking":0.0,"award-numbers":0.0,"update-policies":0.0,"resource-links":0.0,"open-references":0.0}},"backfile":{"journal-article":{"last-status-check-time":1576120333374,"affiliations":0.0,"abstracts":0.0,"orcids":0.0,"licenses":0.0,"references":0.0,"funders":0.0,"similarity-checking":0.0,"award-numbers":0.0,"update-policies":0.0,"resource-links":0.0,"open-references":0.0}},"current":null},"flags":{"deposits-abstracts-current":false,"deposits-orcids-current":false,"deposits":true,"deposits-affiliations-backfile":false,"deposits-update-policies-backfile":false,"deposits-similarity-checking-backfile":false,"deposits-award-numbers-current":false,"deposits-resource-links-current":false,"deposits-articles":true,"deposits-affiliations-current":false,"deposits-funders-current":false,"deposits-references-backfile":false,"deposits-abstracts-backfile":false,"deposits-licenses-backfile":false,"deposits-award-numbers-backfile":false,"deposits-open-references-backfile":false,"deposits-open-references-current":false,"deposits-references-current":false,"deposits-resource-links-backfile":false,"deposits-orcids-backfile":false,"deposits-funders-backfile":false,"deposits-update-policies-current":false,"deposits-similarity-checking-current":false,"deposits-licenses-current":false},"location":"Suite
800 21 DuPont Circle 21 DuPont Circle Washington DC 20036 United States","names":["Journal
of Vector Ecology","BioOne (Journal of Vector Ecology)"]}]}}'}
headers:
Access-Control-Allow-Headers: [X-Requested-With]
Access-Control-Allow-Origin: ['*']
Connection: [close]
Content-Length: ['6411']
Content-Type: [application/json;charset=UTF-8]
Date: ['Fri, 13 Dec 2019 00:32:05 GMT']
Server: [http-kit]
Vary: [Accept]
X-Rate-Limit-Interval: [1s]
X-Rate-Limit-Limit: ['50']
status: {code: 200, message: OK}
version: 1
37 changes: 37 additions & 0 deletions test/vcr_cassettes/setting_ua_string_prefixes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.22.0 habanero/0.7.2 foo bar]
X-USER-AGENT: [python-requests/2.22.0 habanero/0.7.2 foo bar]
method: GET
uri: https://api.crossref.org/prefixes/10.1016/works?sample=2
response:
body: {string: '{"status":"ok","message-type":"work-list","message-version":"1.0.0","message":{"facets":{},"total-results":16687653,"items":[{"indexed":{"date-parts":[[2019,11,21]],"date-time":"2019-11-21T04:14:14Z","timestamp":1574309654721},"reference-count":0,"publisher":"Elsevier
BV","issue":"3","license":[{"URL":"https:\/\/www.elsevier.com\/tdm\/userlicense\/1.0\/","start":{"date-parts":[[2006,9,1]],"date-time":"2006-09-01T00:00:00Z","timestamp":1157068800000},"delay-in-days":0,"content-version":"tdm"}],"content-domain":{"domain":[],"crossmark-restriction":false},"short-container-title":["Communist
and Post-Communist Studies"],"published-print":{"date-parts":[[2006,9]]},"DOI":"10.1016\/s0967-067x(06)00032-8","type":"journal-article","created":{"date-parts":[[2006,9,19]],"date-time":"2006-09-19T16:06:39Z","timestamp":1158681999000},"page":"CO2","source":"Crossref","is-referenced-by-count":0,"title":["Editorial
Board"],"prefix":"10.1016","volume":"39","member":"78","container-title":["Communist
and Post-Communist Studies"],"language":"en","link":[{"URL":"https:\/\/api.elsevier.com\/content\/article\/PII:S0967067X06000328?httpAccept=text\/xml","content-type":"text\/xml","content-version":"vor","intended-application":"text-mining"},{"URL":"https:\/\/api.elsevier.com\/content\/article\/PII:S0967067X06000328?httpAccept=text\/plain","content-type":"text\/plain","content-version":"vor","intended-application":"text-mining"}],"deposited":{"date-parts":[[2019,1,13]],"date-time":"2019-01-13T03:25:37Z","timestamp":1547349937000},"score":1.0,"issued":{"date-parts":[[2006,9]]},"references-count":0,"journal-issue":{"published-print":{"date-parts":[[2006,9]]},"issue":"3"},"alternative-id":["S0967067X06000328"],"URL":"http:\/\/dx.doi.org\/10.1016\/s0967-067x(06)00032-8","ISSN":["0967-067X"],"issn-type":[{"value":"0967-067X","type":"print"}],"subject":["Development","Sociology
and Political Science"]},{"indexed":{"date-parts":[[2019,9,9]],"date-time":"2019-09-09T06:03:37Z","timestamp":1568009017540},"reference-count":18,"publisher":"Elsevier
BV","issue":"1-3","license":[{"URL":"https:\/\/www.elsevier.com\/tdm\/userlicense\/1.0\/","start":{"date-parts":[[2000,1,1]],"date-time":"2000-01-01T00:00:00Z","timestamp":946684800000},"delay-in-days":0,"content-version":"tdm"}],"content-domain":{"domain":[],"crossmark-restriction":false},"short-container-title":["Physica
B: Condensed Matter"],"published-print":{"date-parts":[[2000,1]]},"DOI":"10.1016\/s0921-4526(99)00692-4","type":"journal-article","created":{"date-parts":[[2002,7,25]],"date-time":"2002-07-25T23:23:27Z","timestamp":1027639407000},"page":"34-39","source":"Crossref","is-referenced-by-count":26,"title":["Preisach-type
hysteresis models in magnetic field computation"],"prefix":"10.1016","volume":"275","author":[{"given":"O","family":"Bottauscio","sequence":"first","affiliation":[]},{"given":"M","family":"Chiampi","sequence":"additional","affiliation":[]},{"given":"D","family":"Chiarabaglio","sequence":"additional","affiliation":[]},{"given":"M","family":"Repetto","sequence":"additional","affiliation":[]}],"member":"78","container-title":["Physica
B: Condensed Matter"],"language":"en","link":[{"URL":"https:\/\/api.elsevier.com\/content\/article\/PII:S0921452699006924?httpAccept=text\/xml","content-type":"text\/xml","content-version":"vor","intended-application":"text-mining"},{"URL":"https:\/\/api.elsevier.com\/content\/article\/PII:S0921452699006924?httpAccept=text\/plain","content-type":"text\/plain","content-version":"vor","intended-application":"text-mining"}],"deposited":{"date-parts":[[2019,4,18]],"date-time":"2019-04-18T04:29:24Z","timestamp":1555561764000},"score":1.0,"issued":{"date-parts":[[2000,1]]},"references-count":18,"journal-issue":{"published-print":{"date-parts":[[2000,1]]},"issue":"1-3"},"alternative-id":["S0921452699006924"],"URL":"http:\/\/dx.doi.org\/10.1016\/s0921-4526(99)00692-4","ISSN":["0921-4526"],"issn-type":[{"value":"0921-4526","type":"print"}],"subject":["Electrical
and Electronic Engineering","Electronic, Optical and Magnetic Materials","Condensed
Matter Physics"]}],"items-per-page":20,"query":{"start-index":0,"search-terms":null}}}'}
headers:
Access-Control-Allow-Headers: [X-Requested-With]
Access-Control-Allow-Origin: ['*']
Connection: [close]
Content-Length: ['4162']
Content-Type: [application/json;charset=UTF-8]
Date: ['Fri, 13 Dec 2019 00:34:31 GMT']
Server: [http-kit]
Vary: [Accept]
X-Rate-Limit-Interval: [1s]
X-Rate-Limit-Limit: ['50']
status: {code: 200, message: OK}
version: 1
26 changes: 26 additions & 0 deletions test/vcr_cassettes/setting_ua_string_registration_agency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.22.0 habanero/0.7.2 foo bar]
X-USER-AGENT: [python-requests/2.22.0 habanero/0.7.2 foo bar]
method: GET
uri: https://api.crossref.org/works/10.1126/science.169.3946.635/agency
response:
body: {string: '{"status":"ok","message-type":"work-agency","message-version":"1.0.0","message":{"DOI":"10.1126\/science.169.3946.635","agency":{"id":"crossref","label":"Crossref"}}}'}
headers:
Access-Control-Allow-Headers: [X-Requested-With]
Access-Control-Allow-Origin: ['*']
Connection: [close]
Content-Length: ['166']
Content-Type: [application/json;charset=UTF-8]
Date: ['Fri, 13 Dec 2019 00:36:34 GMT']
Server: [http-kit]
Vary: [Accept]
X-Rate-Limit-Interval: [1s]
X-Rate-Limit-Limit: ['50']
status: {code: 200, message: OK}
version: 1

0 comments on commit 0790a4e

Please sign in to comment.