Added MemoryCacheHandler (#670)

* Added `MemoryCacheHandler`, a cache handler that simply stores the token info in memory as an instance attribute of this class.

* Fixed a bug in `CacheFileHandler.__init__`: The documentation says that the username will be retrieved from the environment, but it wasn't.
This commit is contained in:
Peter Schorn authored and GitHub committed 2021-04-14 16:59:37 +01:00
1 parent 36bdeb0a65
commit 07915e21e5
3 files changed
+34 -16

No files matched your search

+2 -14
View File
@@ -6,7 +6,7 @@ import unittest
import six.moves.urllib.parse as urllibparse
from spotipy import SpotifyOAuth, SpotifyImplicitGrant, SpotifyPKCE
from spotipy.cache_handler import CacheHandler
from spotipy.cache_handler import MemoryCacheHandler
from spotipy.oauth2 import SpotifyClientCredentials, SpotifyOauthError
from spotipy.oauth2 import SpotifyStateError
@@ -51,18 +51,6 @@ def _make_pkceauth(*args, **kwargs):
return SpotifyPKCE("CLID", "REDIR", "STATE", *args, **kwargs)
class MemoryCache(CacheHandler):
def __init__(self, token_info=None):
self.token_info = token_info
def get_cached_token(self):
return self.token_info
def save_token_to_cache(self, token_info):
self.token_info = token_info
return None
class OAuthCacheTest(unittest.TestCase):
@patch.multiple(SpotifyOAuth,
@@ -161,7 +149,7 @@ class OAuthCacheTest(unittest.TestCase):
scope = "playlist-modify-private"
tok = _make_fake_token(1, 1, scope)
spot = _make_oauth(scope, cache_handler=MemoryCache())
spot = _make_oauth(scope, cache_handler=MemoryCacheHandler())
spot.cache_handler.save_token_to_cache(tok)
cached_tok = spot.cache_handler.get_cached_token()