Example #1
0
def test_credentials_are_refreshed_when_invalid(storage_get):
    with patch.object(GfitAPI, 'refresh_credentials') as refresh_creds,\
            patch('gfitpy.gfit_api.Storage') as storage:
        storage.return_value.get.return_value = storage_get

        api = GfitAPI({})

        ret = api.get_credentials()

    # refresh_credentials was not called
    assert refresh_creds.call_args_list == [call(storage.return_value)]
    assert ret == refresh_creds.return_value
Example #2
0
def test_credentials_are_not_touched_when_valid(storage, refresh_creds):
    storage = storage.return_value
    # storage returns something that is valid
    storage.get.return_value = Mock(invalid=False)

    api = GfitAPI({})

    ret = api.get_credentials()

    # refresh_credentials was not called
    assert refresh_creds.call_args_list == []
    assert ret == storage.get.return_value