How to use habanero - 10 common examples

To help you get started, we’ve selected a few habanero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sckott / habanero / test / test-journals.py View on Github external
@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/journals_fail_limit.yaml')
def test_journals_fail_limit():
    "journals - fails on wrong input type to limit"
    cr.journals(limit = 'things')
github sckott / habanero / test / test-journals.py View on Github external
"""Tests for Crossref.journals"""
import os
import vcr
from nose.tools import *
from habanero import exceptions

from habanero import Crossref
cr = Crossref()

@vcr.use_cassette('test/vcr_cassettes/journals.yaml')
def test_journals():
    "journals - basic test"
    res = cr.journals(limit = 1)
    assert dict == res.__class__
    assert dict == res['message'].__class__
    assert 1 == res['message']['items-per-page']

@vcr.use_cassette('test/vcr_cassettes/journals_query.yaml')
def test_journals_query():
    "journals - param: query"
    res = cr.journals(query = "ecology", limit = 2)
    assert dict == res.__class__
    assert 2 == res['message']['items-per-page']
    assert 'journal-list' == res['message-type']
github sckott / habanero / test / test-settings.py View on Github external
"""Tests for user agent strings via the ua_string setting"""
import os
import vcr
import yaml
from nose.tools import *
from habanero import Crossref

cr_with_ua = Crossref(ua_string = "foo bar")
cr_without_ua = Crossref()
cr_with_bad_ua = Crossref(ua_string = 5)

vcr_path = 'test/vcr_cassettes/setting_ua_string.yaml'
@vcr.use_cassette(vcr_path)
def test_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)
    heads = xy['interactions'][0]['request']['headers']
    
    assert 'foo bar' in heads['User-Agent'][0]
    assert 'foo bar' in heads['X-USER-AGENT'][0]

vcr_noua_path = 'test/vcr_cassettes/setting_no_ua_string.yaml'
github sckott / habanero / test / test-settings.py View on Github external
"""Tests for user agent strings via the ua_string setting"""
import os
import vcr
import yaml
from nose.tools import *
from habanero import Crossref

cr_with_ua = Crossref(ua_string = "foo bar")
cr_without_ua = Crossref()
cr_with_bad_ua = Crossref(ua_string = 5)

vcr_path = 'test/vcr_cassettes/setting_ua_string.yaml'
@vcr.use_cassette(vcr_path)
def test_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)
    heads = xy['interactions'][0]['request']['headers']
    
    assert 'foo bar' in heads['User-Agent'][0]
    assert 'foo bar' in heads['X-USER-AGENT'][0]

vcr_noua_path = 'test/vcr_cassettes/setting_no_ua_string.yaml'
@vcr.use_cassette(vcr_noua_path)
github Xunius / MeiTingTrunk / lib / testcrossref.py View on Github external
if __name__=='__main__':

    doi='10.1126/science.169.3946.635'
    doi='10.1175/1520-0477(2001)082<1377:IOGPPT>2.3.CO;2k'
    doi='10.1029/2002JD002499'
    doi='10.1175/1525-7541(2003)004<1147:tvgpcp>2.0.co;2'

    aa=cn.content_negotiation(ids = doi, format = "bibentry")
    cr=Crossref(mailto='xugzhi1987@gmail.com')
    works=cr.works(ids=doi)
    pprint(works)

    bb=crossRefToMetaDict(works['message'])
    print(bb)

    '''
    eti=Etiquette('MeiTing-Trunk', 'v0.1alpha', 'not published yet',
            'xugzhi1987@gmail.com')
    print(str(eti))
    works=Works(etiquette=eti)
    #aa=works.doi('10.1590/0102-311x00133115')
    aa=works.doi(doi)
    pprint(aa)

    bb=crossRefToMetaDict(aa)
github sckott / habanero / test / test-content_negotation.py View on Github external
def test_content_negotiation_alt_url():
    "content negotiation - alternative url"
    res = cn.content_negotiation(ids = '10.1126/science.169.3946.635', url = "http://doi.org")
    assert str == str(res).__class__
github sckott / habanero / test / test-content_negotation.py View on Github external
def test_content_negotiation():
    "content negotiation - default - bibtex"
    res = cn.content_negotiation(ids = '10.1126/science.169.3946.635')
    assert str == str(res).__class__
github sckott / habanero / test / test-content_negotation.py View on Github external
def test_content_negotiation_raises_an_http_error_with_bad_requests():
    "content negotiation - raises an HTTPError with bad requests"
    res = cn.content_negotiation(ids = '10.1126/foo')
github sckott / habanero / test / test-types.py View on Github external
@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')
github sckott / habanero / test / test-prefixes.py View on Github external
@raises(exceptions.RequestError)
@vcr.use_cassette('test/vcr_cassettes/prefixes_filters_not_allowed_with_dois.yaml')
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')