def setup_user(cls, request_key): from dropbox.client import DropboxClient request_token = OAuthRequestToken.get(request_key) session = cls.get_session() session.obtain_access_token(request_token) client = DropboxClient(session) account_info = client.account_info() uid = str(account_info['uid']) q = DropboxUser.all().filter('uid = ', uid) if q.count() == 0: user = DropboxUser(uid=uid, email=account_info['email'], display_name=account_info['display_name'], access_key=session.token.key, access_secret=session.token.secret, country=account_info['country']) else: user = q.get() user.email = account_info['email'] user.display_name = account_info['display_name'] user.access_key = session.token.key user.access_secret = session.token.secret user.put_pending_away(_save=False) user.country = account_info['country'] user.put() OAuthRequestToken.delete(request_key) return user
def setUp(self): from netprintbox.data import OAuthRequestToken super(DropboxServiceSetupTest, self).setUp() token = 'oauth_token=token&oauth_token_secret=secret' token = OAuthRequestToken(key=self.key, token=token) token.put() class client(object): @staticmethod def account_info(): return {'uid': self.uid, 'email': 'email', 'display_name': 'display_name', 'country': 'JP', } class session(object): @staticmethod def obtain_access_token(request_token): pass class token(object): key = 'access_key' secret = 'access_secret' import dropbox.client import dropbox.session mock('dropbox.client.DropboxClient', returns=client) mock('dropbox.session.DropboxSession', returns=session)
def build_authorize_url(cls, callback_url): session = cls.get_session() request_token = session.obtain_request_token() token = OAuthRequestToken(key=request_token.key, token=str(request_token)) token.put() return session.build_authorize_url(request_token, callback_url)