def invalid_cache(): r = RefreshToken(invalid_params) a = AccessToken(invalid_params) c = MemCache() c.refresh_token = r c.access_token = a return c
def test_clear(self, valid_refresh_token, valid_access_token): c = MemCache() c.refresh_token = valid_refresh_token c.access_token == valid_access_token c.clear() assert isinstance(c.refresh_token, EmptyToken) assert isinstance(c.access_token, EmptyToken)
def sample_manager(sample_oid, sample_uri, valid_cache): def dummy(*args, **kwargs): return None c = MemCache() m = TDAuthManager(c, sample_oid, sample_uri) m._open_browser = dummy m._start_auth_server = dummy m._stop_auth_server = dummy return m
def test_api_pass_cache(self, set_env, sample_oid, sample_uri, valid_access_token, valid_refresh_token): c = MemCache() c.refresh_token = valid_refresh_token c.access_token = valid_access_token assert valid_access_token.valid is True a = api(consumer_key=sample_oid, callback_url=sample_uri, store_tokens=False, cache=c) assert isinstance(a.cache, MemCache) assert a.cache.refresh_token == c.refresh_token assert a.cache.access_token == c.access_token assert a.cache.access_token.valid is True
def __init__(self, options=None, **kwargs): """ Initialize API object """ kwargs.update(options or {}) # Required parameters self.consumer_key = kwargs["consumer_key"] self.callback_url = kwargs["callback_url"] # Optional optional parameters self.retry_count = kwargs.get("retry_count", 3) self.pause = kwargs.get("pause", 0.5) self.session = _init_session(kwargs.get("session")) tokens = kwargs.get("store_tokens", True) self.store_tokens = os.getenv("TD_STORE_TOKENS", tokens) if self.store_tokens in [True, "true", "True"]: self.store_tokens = True elif self.store_tokens in [False, "false", "False"]: self.store_tokens = False else: raise ValueError("Enter True or False for store_tokens.") self.ssl_dir = DEFAULT_SSL_DIR self.ssl_cert_path = os.path.join(self.ssl_dir, 'cert.pem') self.ssl_key_path = os.path.join(self.ssl_dir, 'key.pem') self.cache = kwargs.get("cache") if self.cache is None: if self.store_tokens is True: self.cache = DiskCache(CONFIG_DIR, self.consumer_key) else: self.cache = MemCache() # Set up an authorization manager self.auth = TDAuthManager(self.cache, self.consumer_key, self.callback_url) # For debugging purposes self.options = kwargs
def test_set_token(self, valid_refresh_token): c = MemCache() c.refresh_token = valid_refresh_token assert c.refresh_token.token == "validtoken" assert c.refresh_token.expires_in == 1000000
def test_default_values(self): c = MemCache() assert isinstance(c.refresh_token, EmptyToken) assert isinstance(c.access_token, EmptyToken)