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' monkeypatch.setattr(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) == [] monkeypatch.setattr(sponsorships, 'get_contact_id_by_username', lambda archive_id: '123') assert sponsorships.get_contact_id_by_username('@username') == '123' monkeypatch.setattr(sponsorships, 'get_sponsorships_by_contact_id', lambda contact_id: ['fake_data']) assert sponsorships.get_sponsored_editions(user) == ['fake_data']
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) == []