Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mekarpeles authored and cdrini committed Dec 26, 2021
1 parent 699085f commit 2db9b94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 3 additions & 3 deletions openlibrary/core/sponsorships.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def eligibility_check(edition, patron=None):
def get_sponsored_editions_civi(user):
"""
Deprecated by get_sponsored_editions but worth maintaining as we
may periodicaly have to programatically access data from civi
may periodically have to programmatically access data from civi
since it is the ground-truth of this data.
Gets a list of books from the civi API which internet archive
Expand All @@ -54,9 +54,9 @@ def get_sponsored_editions_civi(user):
return {}


def get_sponsored_editions(user, page=1, civi=False):
def get_sponsored_editions(user, page=1):
"""
Gets a list of books from the civi API which internet archive
Gets a list of books from archive.org elasticsearch
@archive_username has sponsored
:param user user: infogami user
Expand Down
28 changes: 26 additions & 2 deletions openlibrary/tests/core/test_sponsors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@


class TestSponsorship:

def test_get_sponsored_editions(self, monkeypatch):
user = storage(key='/person/mekBot')

monkeypatch.setattr(
sponsorships, 'get_internet_archive_id', lambda user_key: '@username'
)
assert sponsorships.get_internet_archive_id(user) == '@username'

class RequestMock(dict):
def __init__(self, *arg):
super().__init__(*arg)

def json(self):
return self

monkeypatch.setattr(
sponsorships.requests, 'get', lambda url, **kwargs:
RequestMock({'response': {'docs': []}})
)

assert sponsorships.get_sponsored_editions(user) == []


def test_get_sponsored_editions_civi(self, monkeypatch):
user = storage(key='/person/mekBot')

monkeypatch.setattr(
sponsorships, 'get_internet_archive_id', lambda user_key: '@username'
)
Expand All @@ -15,7 +39,7 @@ def test_get_sponsored_editions(self, monkeypatch):
sponsorships, 'get_contact_id_by_username', lambda archive_id: None
)
assert sponsorships.get_contact_id_by_username('@username') is None
assert sponsorships.get_sponsored_editions(user) == []
assert sponsorships.get_sponsored_editions_civi(user) == []

monkeypatch.setattr(
sponsorships, 'get_contact_id_by_username', lambda archive_id: '123'
Expand All @@ -26,7 +50,7 @@ def test_get_sponsored_editions(self, monkeypatch):
'get_sponsorships_by_contact_id',
lambda contact_id: ['fake_data'],
)
assert sponsorships.get_sponsored_editions(user) == ['fake_data']
assert sponsorships.get_sponsored_editions_civi(user) == ['fake_data']

def test_do_we_want_it(self, monkeypatch, mock_site):
isbn = '0123456789'
Expand Down

0 comments on commit 2db9b94

Please sign in to comment.