本文整理匯總了Python中pybossa.uploader.rackspace.RackspaceUploader.upload_file方法的典型用法代碼示例。如果您正苦於以下問題:Python RackspaceUploader.upload_file方法的具體用法?Python RackspaceUploader.upload_file怎麽用?Python RackspaceUploader.upload_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pybossa.uploader.rackspace.RackspaceUploader
的用法示例。
在下文中一共展示了RackspaceUploader.upload_file方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_rackspace_uploader_upload_wrong_file
# 需要導入模塊: from pybossa.uploader.rackspace import RackspaceUploader [as 別名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import upload_file [as 別名]
def test_rackspace_uploader_upload_wrong_file(self, mock, mock2):
"""Test RACKSPACE UPLOADER upload wrong file extension works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
mycf.upload_file.return_value = True
u = RackspaceUploader()
u.init_app(self.flask_app)
file = FileStorage(filename='test.docs')
err_msg = "Upload file should return False"
res = u.upload_file(file, container='user_3')
assert res is False, err_msg
示例2: test_rackspace_uploader_upload_file_fails
# 需要導入模塊: from pybossa.uploader.rackspace import RackspaceUploader [as 別名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import upload_file [as 別名]
def test_rackspace_uploader_upload_file_fails(self, mock, mock2):
"""Test RACKSPACE UPLOADER upload file fail works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
from pyrax.exceptions import UploadFailed
mycf.upload_file.side_effect = UploadFailed
u = RackspaceUploader()
u.init_app(self.flask_app)
file = FileStorage(filename='test.jpg')
err_msg = "Upload file should return False"
assert u.upload_file(file, container='user_3') is False, err_msg
示例3: test_rackspace_uploader_upload_file_object_fails
# 需要導入模塊: from pybossa.uploader.rackspace import RackspaceUploader [as 別名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import upload_file [as 別名]
def test_rackspace_uploader_upload_file_object_fails(self, mock, mock2):
"""Test RACKSPACE UPLOADER upload file object fail works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
from pyrax.exceptions import NoSuchObject
container = MagicMock()
container.get_object.side_effect = NoSuchObject
mycf.get_container.return_value = container
u = RackspaceUploader()
u.init_app(self.flask_app)
file = FileStorage(filename='test.jpg')
err_msg = "Upload file should return True"
assert u.upload_file(file, container='user_3') is True, err_msg
示例4: test_rackspace_uploader_upload_correct_file
# 需要導入模塊: from pybossa.uploader.rackspace import RackspaceUploader [as 別名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import upload_file [as 別名]
def test_rackspace_uploader_upload_correct_file(self, mock, mock2):
"""Test RACKSPACE UPLOADER upload file works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
mycf.upload_file.return_value=True
mycf.get_object.side_effect = NoSuchObject
u = RackspaceUploader()
u.init_app(self.flask_app)
file = FileStorage(filename='test.jpg')
err_msg = "Upload file should return True"
assert u.upload_file(file, container='user_3') is True, err_msg
calls = [call.get_container('user_3'),
call.get_container().get_object('test.jpg')]
mycf.assert_has_calls(calls, any_order=True)