本文整理汇总了Python中pybossa.uploader.rackspace.RackspaceUploader.init_app方法的典型用法代码示例。如果您正苦于以下问题:Python RackspaceUploader.init_app方法的具体用法?Python RackspaceUploader.init_app怎么用?Python RackspaceUploader.init_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybossa.uploader.rackspace.RackspaceUploader
的用法示例。
在下文中一共展示了RackspaceUploader.init_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rackspace_uploader_upload_wrong_file
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [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 init_app [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_file_exists_for_missing_file
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_file_exists_for_missing_file(self, credentials):
"""Test RACKSPACE UPLOADER file_exists returns False if the file does not exist"""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
u = RackspaceUploader()
u.init_app(self.flask_app)
container = MagicMock()
container.get_object.side_effect = NoSuchObject
mycf.get_container.return_value = container
file_exists = u.file_exists('noexist.txt', 'mycontainer')
mycf.get_container.assert_called_with('mycontainer')
assert file_exists is False
示例4: test_rackspace_uploader_delete
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_delete(self, mock1):
"""Test RACKSPACE UPLOADER delete method works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
calls = [call.get_container('container'),
call.get_container().get_object('file'),
call.get_container().get_object().delete()
]
u = RackspaceUploader()
u.init_app(self.flask_app)
err_msg = "It should return True"
assert u.delete_file('file', 'container') is True, err_msg
mycf.assert_has_calls(calls, any_order=True)
示例5: test_rackspace_uploader_upload_file_object_fails
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [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
示例6: test_rackspace_uploader_upload_correct_file
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [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)
示例7: test_rackspace_uploader_delete_fails
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_delete_fails(self, mock1):
"""Test RACKSPACE UPLOADER delete fails method works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
container = MagicMock()
container.get_object.side_effect = NoSuchObject
mycf.get_container.return_value = container
calls = [call.get_container('container')]
u = RackspaceUploader()
u.init_app(self.flask_app)
err_msg = "It should return False"
assert u.delete_file('file', 'container') is False, err_msg
mycf.assert_has_calls(calls, any_order=True)
示例8: test_file_exists_for_real_file
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_file_exists_for_real_file(self, credentials):
"""Test RACKSPACE UPLOADER file_exists returns True if the file exists"""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
u = RackspaceUploader()
u.init_app(self.flask_app)
filename='test.jpg'
container = MagicMock()
container.get_object.return_value = "Real File"
mycf.get_container.return_value = container
file_exists = u.file_exists(filename, 'mycontainer')
mycf.get_container.assert_called_with('mycontainer')
container.get_object.assert_called_with(filename)
assert file_exists is True
示例9: test_rackspace_uploader_lookup_url_none
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_lookup_url_none(self, mock1):
"""Test RACKSPACE UPLOADER lookup returns None for non enabled CDN."""
filename = 'test.jpg'
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
cdn_enabled_mock = PropertyMock(return_value=False)
type(fake_container).cdn_enabled = cdn_enabled_mock
mycf.get_container.return_value = fake_container
u = RackspaceUploader()
u.init_app(self.flask_app)
res = u._lookup_url('rackspace', {'filename': filename,
'container': 'user_3'})
err_msg = "We should get the None"
assert res is None, err_msg
示例10: test_rackspace_uploader_get_container
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_get_container(self, mock1):
"""Test RACKSPACE UPLOADER get_container method works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
cdn_enabled_mock = PropertyMock(return_value=False)
type(fake_container).cdn_enabled = cdn_enabled_mock
mycf.get_container.side_effect = NoSuchContainer
calls = [call.get_container('user_3'),
call.create_container('user_3'),
call.make_container_public('user_3')
]
u = RackspaceUploader()
u.init_app(self.flask_app)
assert u.get_container('user_3')
mycf.assert_has_calls(calls, any_order=True)
示例11: test_rackspace_uploader_lookup_url_returns_failover_url_project
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_lookup_url_returns_failover_url_project(self, mock):
"""Test RACKSPACE UPLOADER lookup returns failover_url for project avatar."""
filename = 'project_32.jpg'
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
cdn_enabled_mock = PropertyMock(return_value=False)
type(fake_container).cdn_enabled = cdn_enabled_mock
mycf.get_container.return_value = fake_container
fake_container.make_public.side_effect = NoSuchObject
u = RackspaceUploader()
u.init_app(self.flask_app)
res = u._lookup_url('rackspace', {'filename': filename,
'container': 'user_3'})
failover_url = 'https://localhost/static/img/placeholder.project.png'
err_msg = "We should get the %s but we got %s " % (failover_url, res)
assert res == failover_url, err_msg
示例12: test_rackspace_uploader_lookup_url
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_lookup_url(self, mock1, mock2):
"""Test RACKSPACE UPLOADER lookup returns a valid link."""
uri = 'https://rackspace.com'
filename = 'test.jpg'
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
cdn_enabled_mock = PropertyMock(return_value=True)
type(fake_container).cdn_enabled = cdn_enabled_mock
mycf.get_container.return_value = fake_container
u = RackspaceUploader()
u.init_app(self.flask_app)
res = u._lookup_url('rackspace', {'filename': filename,
'container': 'user_3'})
expected_url = "%s/%s" % (uri, filename)
err_msg = "We should get the following URL: %s" % expected_url
assert res == expected_url, err_msg
示例13: test_rackspace_uploader_lookup_url_enable_cdn
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_lookup_url_enable_cdn(self, mock1, mock2):
"""Test RACKSPACE UPLOADER lookup enables CDN for non enabled CDN."""
filename = 'test.jpg'
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
cdn_enabled_mock = PropertyMock(return_value=False)
type(fake_container).cdn_enabled = cdn_enabled_mock
mycf.get_container.return_value = fake_container
u = RackspaceUploader()
u.init_app(self.flask_app)
res = u._lookup_url('rackspace', {'filename': filename,
'container': 'user_3'})
url = 'https://rackspace.com/test.jpg'
err_msg = "We should get the %s but we got %s " % (url, res)
assert res == url, err_msg
calls = [call.make_public()]
fake_container.assert_has_calls(calls, any_order=True)
示例14: test_rackspace_uploader_creates_container
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_creates_container(self, mock, mock2):
"""Test RACKSPACE UPLOADER creates container works."""
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
mycf.get_container.side_effect = NoSuchContainer
mycf.create_container.return_value = True
mycf.make_container_public.return_value = True
u = RackspaceUploader()
res = u.init_app(self.flask_app)
err_msg = "Init app should return the container."
assert res is True, err_msg
示例15: test_rackspace_uploader_init
# 需要导入模块: from pybossa.uploader.rackspace import RackspaceUploader [as 别名]
# 或者: from pybossa.uploader.rackspace.RackspaceUploader import init_app [as 别名]
def test_rackspace_uploader_init(self, Mock):
"""Test RACKSPACE UPLOADER init works."""
new_extensions = ['pdf', 'doe']
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles',
return_value=cloudfiles_mock):
with patch.dict(self.flask_app.config,
{'ALLOWED_EXTENSIONS': new_extensions}):
with patch('pybossa.uploader.rackspace.pyrax.cloudfiles') as mycf:
mycf.get_container.return_value = True
u = RackspaceUploader()
res = u.init_app(self.flask_app, cont_name='mycontainer')
err_msg = "It should return the container."
assert res is True, err_msg
err_msg = "The container name should be updated."
assert u.cont_name == 'mycontainer', err_msg
for ext in new_extensions:
err_msg = "The .%s extension should be allowed" % ext
assert ext in u.allowed_extensions, err_msg