def setUp(self): super(TestConfigViews, self).setUp() self.user.add_addon('box') settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='not none', access_token='Nah') oauth.save() settings.oauth_settings = oauth settings.save()
def setUp(self): super(TestFilebrowserViews, self).setUp() self.user.add_addon('box') settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='not none', access_token='Nah') oauth.save() settings.oauth_settings = oauth settings.save() self.patcher = mock.patch('website.addons.box.model.BoxNodeSettings.fetch_folder_name') self.patcher.return_value = 'Camera Uploads' self.patcher.start()
def setUp(self): super(TestFilebrowserViews, self).setUp() self.user.add_addon('box') settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='not none', access_token='Nah') oauth.save() settings.oauth_settings = oauth settings.save() self.patcher = mock.patch( 'website.addons.box.model.BoxNodeSettings.fetch_folder_name') self.patcher.return_value = 'Camera Uploads' self.patcher.start()
class BoxAddonTestCase(AddonTestCase): ADDON_SHORT_NAME = 'box' def set_user_settings(self, settings): self.oauth = BoxOAuthSettings( user_id='test', access_token='test') self.oauth.save() settings.oauth_settings = self.oauth def set_node_settings(self, settings): settings.folder_id = '1234567890'
def test_box_oauth_delete_user(self, mock_disable_access_token): self.user.add_addon('box') settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='fa;l', access_token='a;lkjadl;kas') oauth.save() settings.oauth_settings = oauth settings.save() assert_true(settings.has_auth) self.user.save() url = api_url_for('box_oauth_delete_user') self.app.delete(url) settings.reload() assert_false(settings.has_auth)
def box_oauth_finish(auth, **kwargs): """View called when the Oauth flow is completed. Adds a new BoxUserSettings record to the user and saves the user's access token and account info. """ user = auth.user node = Node.load(session.data.pop('box_auth_nid', None)) # Handle request cancellations from Box's API if request.args.get('error'): flash('Box authorization request cancelled.') if node: return redirect(node.web_url_for('node_setting')) return redirect(web_url_for('user_addons')) result = finish_auth() # If result is a redirect response, follow the redirect if isinstance(result, BaseResponse): return result client = BoxClient(CredentialsV2( result['access_token'], result['refresh_token'], settings.BOX_KEY, settings.BOX_SECRET, )) about = client.get_user_info() oauth_settings = BoxOAuthSettings.load(about['id']) if not oauth_settings: oauth_settings = BoxOAuthSettings(user_id=about['id'], username=about['name']) oauth_settings.save() oauth_settings.refresh_token = result['refresh_token'] oauth_settings.access_token = result['access_token'] oauth_settings.expires_at = datetime.utcfromtimestamp(time.time() + 3600) # Make sure user has box enabled user.add_addon('box') user.save() user_settings = user.get_addon('box') user_settings.oauth_settings = oauth_settings user_settings.save() flash('Successfully authorized Box', 'success') if node: # Automatically use newly-created auth if node.has_addon('box'): node_addon = node.get_addon('box') node_addon.set_user_auth(user_settings) node_addon.save() return redirect(node.web_url_for('node_setting')) return redirect(web_url_for('user_addons'))
def test_cant_start_oauth_if_already_authorized(self): # User already has box authorized self.user.add_addon('box') self.user.save() settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='fa;l', access_token='a;lkjadl;kas') oauth.save() settings.oauth_settings = oauth settings.save() assert_true(self.user.get_addon('box').has_auth) # Tries to start oauth again url = api_url_for('box_oauth_start_user') res = self.app.get(url).follow() # Is redirected back to settings page assert_equal(res.request.path, web_url_for('user_addons'))
def test_cant_start_oauth_if_already_authorized(self): # User already has box authorized self.user.add_addon('box') self.user.save() settings = self.user.get_addon('box') oauth = BoxOAuthSettings(user_id='fa;l', access_token='a;lkjadl;kas') oauth.save() settings.oauth_settings = oauth settings.save() assert_true(self.user.get_addon('box').has_auth) # Tries to start oauth again url = api_url_for('box_oauth_start_user') res = self.app.get(url).follow() # Is redirected back to settings page assert_equal( res.request.path, web_url_for('user_addons') )
def set_user_settings(self, settings): self.oauth = BoxOAuthSettings( user_id='test', access_token='test') self.oauth.save() settings.oauth_settings = self.oauth