def test_view_functions(self): self.assertIn('dropbox.callback', app.view_functions) self.assertIn('dropbox.logout', app.view_functions) with app.test_request_context(): self.assertEqual(url_for('dropbox.callback'), '/dropbox/callback') self.assertEqual(url_for('dropbox.logout'), '/dropbox/logout')
def test_callback(self): with app.test_request_context(): callback_url = url_for('dropbox.callback') response = self.app.get(callback_url) self.assertEqual(response.status_code, 200) self.assertIn('<h3>Warning</h3>', response.data) self.assertIn( "Dropbox API didn't return valid oAuth token.", response.data ) token = self.token.key response = self.app.get(callback_url + '?oauth_token=%s' % token[::-1]) self.assertEqual(response.status_code, 200) self.assertIn('<h3>Warning</h3>', response.data) self.assertIn( 'Looks like, oAuth token from Dropbox API is broken.', response.data ) response = self.app.get(callback_url + '?oauth_token=%s' % token) self.assertEqual(response.status_code, 200) self.assertIn('<h3>Warning</h3>', response.data) self.assertNotIn( 'Looks like, oAuth token from Dropbox API is broken.', response.data )
def setUp(self): super(TestDropboxViews, self).setUp() self.filename = filename = "redis.pdf" with app.test_request_context(): self.delete_url = url_for("delete", filename=filename) self.download_url = url_for("download", filename=filename) self.home_url = url_for("home") self.list_url = url_for("list") self.media_url = url_for("media", filename=filename) self.success_url = url_for("success", filename=filename) self.upload_url = url_for("upload") self.old_build_authorize_url = DropboxSession.build_authorize_url dropbox_url = "https://www.dropbox.com/login" DropboxSession.build_authorize_url = MagicMock(return_value=dropbox_url) self.old_obtain_request_token = DropboxSession.obtain_request_token token = "".join(choice(letters + digits) for _ in range(12)) secret = "".join(choice(letters + digits) for _ in range(16)) self.token = OAuthToken(token, secret) DropboxSession.obtain_request_token = MagicMock(return_value=self.token)
def test_dropbox_callback_url(self): callback_url = "http://localhost/dropbox-callback" quoted_url = urllib.urlencode({"oauth_callback": callback_url}) app.config["DROPBOX_CALLBACK_URL"] = callback_url dropbox_obj = Dropbox(app) with app.test_request_context(): self.assertIn(quoted_url, dropbox_obj.login_url)
def test_dropbox_callback_url(self): callback_url = 'http://localhost/dropbox-callback' quoted_url = urllib.parse.urlencode({'oauth_callback': callback_url}) app.config['DROPBOX_CALLBACK_URL'] = callback_url dropbox_obj = Dropbox(app) with app.test_request_context(): self.assertIn(quoted_url, dropbox_obj.login_url)
def test_view_functions(self): self.assertIn("dropbox.callback", app.view_functions) self.assertIn("dropbox.logout", app.view_functions) with app.test_request_context(): url = url_for("dropbox.callback") self.assertTrue(url.endswith("/callback")) url = url_for("dropbox.logout") self.assertTrue(url.endswith("/logout"))
def test_dropbox_login_url(self): with app.test_request_context(): callback_url = url_for("dropbox.callback", _external=True) quoted_url = urllib.urlencode({"oauth_callback": callback_url}) first_url = dropbox.login_url self.assertIn(quoted_url, first_url) second_url = dropbox.login_url self.assertIn(quoted_url, second_url) self.assertNotEqual(first_url, second_url)
def test_dropbox_login_url(self): with app.test_request_context(): callback_url = url_for('dropbox.callback', _external=True) quoted_url = urllib.parse.urlencode({'oauth_callback': callback_url}) first_url = dropbox.login_url self.assertIn(quoted_url, first_url) second_url = dropbox.login_url self.assertIn(quoted_url, second_url) self.assertNotEqual(first_url, second_url)
def tearDown(self): DropboxSession.build_authorize_url = self.old_build_authorize_url DropboxSession.obtain_request_token = self.old_obtain_request_token old_methods = ("account_info", "file_delete", "get_file_and_metadata", "media", "metadata") for method in old_methods: attr = "old_" + method if hasattr(self, attr): setattr(DropboxClient, method, getattr(self, attr)) with app.test_request_context(): dropbox.logout() super(TestDropboxViews, self).tearDown()
def tearDown(self): DropboxSession.build_authorize_url = self.old_build_authorize_url DropboxSession.obtain_request_token = self.old_obtain_request_token old_methods = ('account_info', 'file_delete', 'get_file_and_metadata', 'media', 'metadata') for method in old_methods: attr = 'old_' + method if hasattr(self, attr): setattr(DropboxClient, method, getattr(self, attr)) with app.test_request_context(): dropbox.logout() super(TestDropboxViews, self).tearDown()
def setUp(self): super(TestDropboxViews, self).setUp() self.filename = filename = 'redis.pdf' with app.test_request_context(): self.delete_url = url_for('delete', filename=filename) self.download_url = url_for('download', filename=filename) self.home_url = url_for('home') self.files_url = url_for('files') self.media_url = url_for('media', filename=filename) self.success_url = url_for('success', filename=filename) self.upload_url = url_for('upload') self.old_build_authorize_url = DropboxSession.build_authorize_url dropbox_url = 'https://www.dropbox.com/login' DropboxSession.build_authorize_url = \ MagicMock(return_value=dropbox_url) self.old_obtain_request_token = DropboxSession.obtain_request_token DropboxSession.obtain_request_token = \ MagicMock(return_value=self.token)
def test_safe_url_for(self): with app.test_request_context(): self.assertEqual(url_for('home'), '/') self.assertRaises(RoutingBuildError, url_for, 'does_not_exist') self.assertEqual(safe_url_for('does_not_exist'), 'does_not_exist')
def test_dropbox_logout_not_logged_in(self): with app.test_request_context(): self.assertNotIn(DROPBOX_ACCESS_TOKEN_KEY, session) dropbox.logout() self.assertNotIn(DROPBOX_ACCESS_TOKEN_KEY, session)
def test_safe_url_for(self): with app.test_request_context(): self.assertEqual(url_for("home"), "/") self.assertRaises(RoutingBuildError, url_for, "does_not_exist") self.assertEqual(safe_url_for("does_not_exist"), "does_not_exist")
def test_dropbox_logout_url(self): with app.test_request_context(): self.assertEqual(url_for("dropbox.logout"), dropbox.logout_url)
def test_dropbox_logout_url(self): with app.test_request_context(): self.assertEqual(url_for('dropbox.logout'), dropbox.logout_url)