Created
October 10, 2018 11:39
-
-
Save pavelpy/147660baa0dcf781d055c5fc703802d7 to your computer and use it in GitHub Desktop.
Revisions
-
pavelpy created this gist
Oct 10, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ """ >>> api_instance = BypassApiKey(RemoteServerApi()) >>> api_instance.method_that_need_access_token(1, 2, 3) [(1, 2, 3), {'access_token': 'test'}] """ import functools ACCESS_TOKEN = 'test' class RemoteServerApi: def method_that_need_access_token(self, *args, **kwargs): if 'access_token' in kwargs: return [args, kwargs] else: raise Exception('I will not work without access_token') def bypass_api_key(func): @functools.wraps(func) def wrapper_decorator(*args, **kwargs): kwargs.update(dict(access_token=ACCESS_TOKEN)) value = func(*args, **kwargs) return value return wrapper_decorator class BypassApiKey: def __init__(self, class_instance): self.class_instance = class_instance def __getattr__(self, item): return bypass_api_key(getattr(self.class_instance, item))