示例#1
0
def test_token_cache_hit(mocker, empty_token_cache):
    connector = woot.WootricConnector(
        name='wootric', type='wootric', client_id='cid', client_secret='cs'
    )
    responses.add(
        responses.POST,
        'https://api.wootric.com/oauth/token',
        json={'access_token': 'x', 'expires_in': 10},
    )
    mocker.spy(woot.WootricConnector, 'fetch_access_token')
    assert woot.access_token(connector) == 'x'
    assert woot.access_token(connector) == 'x'
    # fetch_access_token should have been called only once despite `access_token()`
    # was called twice
    assert connector.fetch_access_token.call_count == 1
示例#2
0
def test_token_cache_miss(mocker, empty_token_cache):
    connector = woot.WootricConnector(
        name='wootric', type='wootric', client_id='cid', client_secret='cs'
    )
    # HACK: use a negative expire
    responses.add(
        responses.POST,
        'https://api.wootric.com/oauth/token',
        json={'access_token': 'x', 'expires_in': -10},
    )
    mocker.spy(woot.WootricConnector, 'fetch_access_token')
    assert woot.access_token(connector) == 'x'
    assert woot.access_token(connector) == 'x'
    # fetch_access_token should have been called twice since the token is marked
    # as expired
    assert connector.fetch_access_token.call_count == 2