Skip to content

Commit

Permalink
filled out tests a bit more #30
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jan 13, 2016
1 parent 883aadd commit 429dd50
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/test-cursor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
"""Tests for cursor"""
from nose.tools import *
import os
from habanero import Crossref
cr = Crossref()

def test_cursor_works():
def test_cursor():
"cursor works - basic test"
res = cr.works(query = "widget", cursor = "*", cursor_max = 10)
assert dict == res.__class__
assert dict == res['message'].__class__
assert 4 == len(res)
assert 6 == len(res['message'])

def test_cursor_max():
"cursor works - cursor_max works"
res1 = cr.works(query = "widget", cursor = "*", cursor_max = 60)
items1 = [ z['message']['items'] for z in res1 ]
items1 = [ item for sublist in items1 for item in sublist ]
res2 = cr.works(query = "widget", cursor = "*", cursor_max = 40)
items2 = [ z['message']['items'] for z in res2 ]
items2 = [ item for sublist in items2 for item in sublist ]
assert list == res1.__class__
assert list == res2.__class__
assert 60 == len(items1)
assert 40 == len(items2)

@raises(Exception)
def test_cursor_fails():
"cursor works - fails well"
cr.works(query = "widget", cursor = "thing")
16 changes: 16 additions & 0 deletions test/test-funders.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ def test_funders_sample():
res = cr.funders(sample = 2)
assert dict == res.__class__
assert 20 == res['message']['items-per-page']

@raises(Exception)
def test_funders_filter_fails_noidsworks():
"funders - filter fails, no ids or works"
cr.funders(filter = {'from_pub_date': '2014-03-03'})

@raises(Exception)
def test_funders_filter_fails_noids():
"funders - filter fails, no ids"
cr.funders(works = True, filter = {'has_assertion': True})

def test_funders_filter_works():
"funders - filter fails"
res = cr.funders(ids = '10.13039/100000001', works = True, filter = {'has_assertion': True})
assert dict == res.__class__
assert 20 == res['message']['items-per-page']
5 changes: 5 additions & 0 deletions test/test-journals.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ def test_journals_works():
assert 'work-list' == res1['message-type']
assert max(scores1) == scores1[-1]
assert min(scores2) == scores2[-1]

@raises(Exception)
def test_journals_filter_fails_noidsworks():
"journals - filter fails, no ids or works"
cr.journals(filter = {'from_pub_date': '2014-03-03'})

0 comments on commit 429dd50

Please sign in to comment.