class SimpleTokenCacheTest(unittest.TestCase): def setUp(self): from flickrapi.tokencache import SimpleTokenCache self.tc = SimpleTokenCache() def test_get_set_del(self): self.assertIsNone(self.tc.token) self.tc.token = 'nümbér' self.assertEqual(self.tc.token, 'nümbér') del self.tc.token self.assertIsNone(self.tc.token) self.tc.token = 'nümbér' self.tc.forget() self.assertIsNone(self.tc.token)
class SimpleTokenCacheTest(unittest.TestCase): def setUp(self): from flickrapi.tokencache import SimpleTokenCache self.tc = SimpleTokenCache() def test_get_set_del(self): self.assertIsNone(self.tc.token) self.tc.token = 'nümbér' self.assertEquals(self.tc.token, 'nümbér') del self.tc.token self.assertIsNone(self.tc.token) self.tc.token = 'nümbér' self.tc.forget() self.assertIsNone(self.tc.token)
def __init__(self, api_key, secret=None, username=None, token=None, format='etree', store_token=True, cache=False): """Construct a new FlickrAPI instance for a given API key and secret. api_key The API key as obtained from Flickr. secret The secret belonging to the API key. username Used to identify the appropriate authentication token for a certain user. token If you already have an authentication token, you can give it here. It won't be stored on disk by the FlickrAPI instance. format The response format. Use either "xmlnode" or "etree" to get a parsed response, or use any response format supported by Flickr to get an unparsed response from method calls. It's also possible to pass the ``format`` parameter on individual calls. store_token Disables the on-disk token cache if set to False (default is True). Use this to ensure that tokens aren't read nor written to disk, for example in web applications that store tokens in cookies. cache Enables in-memory caching of FlickrAPI calls - set to ``True`` to use. If you don't want to use the default settings, you can instantiate a cache yourself too: >>> f = FlickrAPI(api_key='123') >>> f.cache = SimpleCache(timeout=5, max_entries=100) """ self.api_key = api_key self.secret = secret self.default_format = format self.__handler_cache = {} if token: # Use a memory-only token cache self.token_cache = SimpleTokenCache() self.token_cache.token = token elif not store_token: # Use an empty memory-only token cache self.token_cache = SimpleTokenCache() else: # Use a real token cache self.token_cache = TokenCache(api_key, username) if cache: self.cache = SimpleCache() else: self.cache = None
def setUp(self): from flickrapi.tokencache import SimpleTokenCache self.tc = SimpleTokenCache()