Skip to content

Commit

Permalink
fix #85 query.title is deprecated, point people to query.bibliographic
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Dec 18, 2019
1 parent 70a3b34 commit a957702
Show file tree
Hide file tree
Showing 17 changed files with 2,197 additions and 2,367 deletions.
2 changes: 1 addition & 1 deletion habanero/__init__.py
Expand Up @@ -39,7 +39,7 @@
'''

__title__ = 'habanero'
__version__ = '0.7.2'
__version__ = '0.7.2.1'
__author__ = 'Scott Chamberlain'
__license__ = 'MIT'

Expand Down
9 changes: 4 additions & 5 deletions habanero/crossref/crossref.py
Expand Up @@ -105,18 +105,17 @@ class Crossref(object):
**Field queries**
One or more field queries. Field queries are searches on specific fields.
For example, using `query_title` searches titles instead of full search
For example, using `query_author` searches author names instead of full search
across all fields as would happen by default. Acceptable set of field
query parameters are:
* `query_title` - Query title and subtitle
* `query_container_title` - Query container-title aka. publication name
* `query_author` - Query author given and family names
* `query_editor` - Query editor given and family names
* `query_chair` - Query chair given and family names
* `query_translator` - Query translator given and family names
* `query_contributor` - Query author, editor, chair and translator given and family names
* `query_bibliographic` - Query bibliographic information, useful for citation look up. Includes titles, authors, ISSNs and publication years
* `query_bibliographic` - Query bibliographic information, useful for citation look up. Includes titles, authors, ISSNs and publication years. Crossref retired `query_title`; use this field query instead
* `query_affiliation` - Query contributor affiliations
.. _sorting:
Expand Down Expand Up @@ -649,7 +648,7 @@ def journals(self, ids = None, query = None, filter = None, offset = None,
res = cr.journals(ids = "2167-8359", works = True, cursor = "*", cursor_max = 200, progress_bar = True)
# field queries
res = cr.journals(ids = "2167-8359", works = True, query_title = 'fish', filter = {'type': 'journal-article'})
res = cr.journals(ids = "2167-8359", works = True, query_bibliographic = 'fish', filter = {'type': 'journal-article'})
[ x.get('title') for x in res['message']['items'] ]
'''
return request(self.mailto, self.ua_string, self.base_url, "/journals/", ids,
Expand Down Expand Up @@ -720,7 +719,7 @@ def types(self, ids = None, query = None, filter = None, offset = None,
res = cr.types(ids = "journal-article", works = True, cursor = "*", cursor_max = 120, progress_bar = True)
# field queries
res = cr.types(ids = "journal-article", works = True, query_title = 'gender', rows = 100)
res = cr.types(ids = "journal-article", works = True, query_bibliographic = 'gender', rows = 100)
[ x.get('title') for x in res['message']['items'] ]
'''
return request(self.mailto, self.ua_string, self.base_url, "/types/", ids,
Expand Down
7 changes: 7 additions & 0 deletions test/test-funders.py
@@ -1,6 +1,7 @@
"""Tests for Crossref.funders"""
import os
import vcr
import requests
from nose.tools import *
from habanero import exceptions

Expand Down Expand Up @@ -81,3 +82,9 @@ def test_funders_field_queries():
def test_funders_query_filters_not_allowed_with_dois():
"funders - param: kwargs - query filters not allowed on works/funderid/ route"
cr.funders(ids = "10.13039/100000001", query_container_title = 'engineering')

@raises(requests.exceptions.HTTPError)
@vcr.use_cassette('test/vcr_cassettes/funders_query_title_not_allowed_anymore.yaml')
def test_funders_query_title_not_allowed_anymore():
"funders - param: kwargs - query_title query not allowed anymore"
res = cr.funders(ids = '10.13039/100000001', works = True, query_title = 'cellular')
14 changes: 10 additions & 4 deletions test/test-journals.py
Expand Up @@ -82,15 +82,21 @@ def test_journals_fail_sort():
@vcr.use_cassette('test/vcr_cassettes/journals_field_queries.yaml')
def test_journals_field_queries():
"journals - param: kwargs - field queries work as expected"
res = cr.journals(ids = "2167-8359", works = True, query_title = 'fish', filter = {'type': 'journal-article'})
res = cr.journals(ids = "2167-8359", works = True, query_bibliographic = 'fish', filter = {'type': 'journal-article'})
titles = [ x.get('title')[0] for x in res['message']['items'] ]
assert dict == res.__class__
assert 5 == len(res['message'])
assert list == titles.__class__
assert str == str(titles[0]).__class__

@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/journals_filters_not_allowed_with_dois.yaml')
def test_journals_query_filters_not_allowed_with_dois():
@vcr.use_cassette('test/vcr_cassettes/journals_field_queries_not_allowed_with_dois.yaml')
def test_journals_field_queries_not_allowed_with_dois():
"journals - param: kwargs - query filters not allowed on works/journalid/ route"
res = cr.journals(ids = "2167-8359", query_title = 'fish')
res = cr.journals(ids = "2167-8359", query_bibliographic = 'fish')

@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/journals_query_title_not_allowed_anymore.yaml')
def test_journals_query_title_not_allowed_anymore():
"journals - param: kwargs - query_title query not allowed anymore"
res = cr.journals(query_title = 'cellular')
9 changes: 7 additions & 2 deletions test/test-members.py
@@ -1,10 +1,9 @@
"""Tests for Crossref.members"""
import os
import vcr
import requests
from nose.tools import *

from habanero import exceptions

from habanero import Crossref
cr = Crossref()

Expand Down Expand Up @@ -53,3 +52,9 @@ def test_members_field_queries():
def test_members_query_filters_not_allowed_with_dois():
"members - param: kwargs - query filters not allowed on works/memberid/ route"
cr.members(ids = 98, query_author = 'carl boettiger')

@raises(requests.exceptions.HTTPError)
@vcr.use_cassette('test/vcr_cassettes/members_query_title_not_allowed_anymore.yaml')
def test_members_query_title_not_allowed_anymore():
"members - param: kwargs - query_title query not allowed anymore"
res = cr.members(ids = 98, works = True, query_title = 'cellular')
6 changes: 6 additions & 0 deletions test/test-prefixes.py
Expand Up @@ -45,3 +45,9 @@ def test_prefixes_query_filters_not_allowed_with_dois():
"prefixes - param: kwargs - query filters not allowed on prefixes/prefix/ route"
cr.prefixes(ids = "10.1371", query_editor = 'cooper')

@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/prefixes_query_title_not_allowed_anymore.yaml')
def test_prefixes_query_title_not_allowed_anymore():
"prefixes - param: kwargs - query_title query not allowed anymore"
res = cr.prefixes(works = True, query_title = 'cellular')

10 changes: 8 additions & 2 deletions test/test-types.py
Expand Up @@ -69,7 +69,7 @@ def test_types_works():
# UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 109: ordinal not in range(128)
# def test_types_field_queries():
# "types - param: kwargs - field queries work as expected"
# res = cr.types(ids = "journal-article", works = True, query_title = 'gender', rows = 20)
# res = cr.types(ids = "journal-article", works = True, query_bibliographic = 'gender', rows = 20)
# titles = [ str(x.get('title')[0]) for x in res['message']['items'] ]
# assert dict == res.__class__
# assert 5 == len(res['message'])
Expand All @@ -80,5 +80,11 @@ def test_types_works():
@vcr.use_cassette('test/vcr_cassettes/types_filters_not_allowed_with_typeid.yaml')
def test_types_query_filters_not_allowed_with_typeid():
"types - param: kwargs - query filters not allowed on types/type/ route"
cr.types(ids = "journal-article", query_title = 'gender')
cr.types(ids = "journal-article", query_bibliographic = 'gender')

@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/types_query_title_not_allowed_anymore.yaml')
def test_types_query_title_not_allowed_anymore():
"types - param: kwargs - query_title query not allowed anymore"
res = cr.types(works = True, query_title = 'cellular')

8 changes: 8 additions & 0 deletions test/test-works.py
@@ -1,7 +1,9 @@
"""Tests for Crossref.works"""
import os
import vcr
import requests
from nose.tools import *
from habanero import exceptions
from habanero import Crossref
from habanero import RequestError
cr = Crossref()
Expand Down Expand Up @@ -85,3 +87,9 @@ def test_works_with_select_param():
res2 = cr.works(query = "ecology", select = ["DOI","title"])
assert res1 == res2
assert list(res2['message']['items'][0].keys()) == ['DOI', 'title']

@raises(requests.exceptions.HTTPError)
@vcr.use_cassette('test/vcr_cassettes/works_query_title_not_allowed_anymore.yaml')
def test_works_query_title_not_allowed_anymore():
"works - param: kwargs - query_title query not allowed anymore"
cr.works(query_title = 'cellular')
23 changes: 23 additions & 0 deletions test/vcr_cassettes/funders_query_title_not_allowed_anymore.yaml
@@ -0,0 +1,23 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.22.0 habanero/0.7.2.1]
X-USER-AGENT: [python-requests/2.22.0 habanero/0.7.2.1]
method: GET
uri: https://api.crossref.org/funders/10.13039/100000001/works?query.title=cellular
response:
body: {string: '{"status":"failed","message-type":"validation-failure","message":[{"type":"unknown-parameter","value":"query.title","message":"Parameter
query.title has been deprecated. Please use query.bibliographic instead. See
https://status.crossref.org/incidents/4y45gj63jsp4 "}]}

'}
headers:
Cache-Control: [no-cache]
Connection: [close]
Content-Type: [application/json]
status: {code: 400, message: Bad Request}
version: 1

0 comments on commit a957702

Please sign in to comment.