• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rackspace.RackspaceUploader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pybossa.uploader.rackspace.RackspaceUploader的典型用法代码示例。如果您正苦于以下问题:Python RackspaceUploader类的具体用法?Python RackspaceUploader怎么用?Python RackspaceUploader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了RackspaceUploader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_rackspace_uploader_creates_container

 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
开发者ID:PyBossa,项目名称:pybossa,代码行数:10,代码来源:test_rackspace_uploader.py


示例2: test_rackspace_uploader_upload_wrong_file

 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
开发者ID:PyBossa,项目名称:pybossa,代码行数:10,代码来源:test_rackspace_uploader.py


示例3: test_rackspace_uploader_upload_file_fails

 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
开发者ID:PyBossa,项目名称:pybossa,代码行数:10,代码来源:test_rackspace_uploader.py


示例4: test_file_exists_for_missing_file

    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
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:test_rackspace_uploader.py


示例5: test_rackspace_uploader_delete

 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)
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:test_rackspace_uploader.py


示例6: test_rackspace_uploader_upload_file_object_fails

 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
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:test_rackspace_uploader.py


示例7: test_rackspace_uploader_upload_correct_file

 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)
开发者ID:PyBossa,项目名称:pybossa,代码行数:13,代码来源:test_rackspace_uploader.py


示例8: test_rackspace_uploader_delete_fails

    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)
开发者ID:PyBossa,项目名称:pybossa,代码行数:13,代码来源:test_rackspace_uploader.py


示例9: test_file_exists_for_real_file

    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
开发者ID:PyBossa,项目名称:pybossa,代码行数:14,代码来源:test_rackspace_uploader.py


示例10: test_rackspace_uploader_lookup_url_none

    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
开发者ID:bcfuchs,项目名称:pybossa,代码行数:14,代码来源:test_rackspace_uploader.py


示例11: test_rackspace_uploader_get_container

    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)
开发者ID:PyBossa,项目名称:pybossa,代码行数:15,代码来源:test_rackspace_uploader.py


示例12: test_rackspace_uploader_lookup_url_returns_failover_url_project

 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
开发者ID:PyBossa,项目名称:pybossa,代码行数:15,代码来源:test_rackspace_uploader.py


示例13: test_rackspace_uploader_lookup_url

    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
开发者ID:PyBossa,项目名称:pybossa,代码行数:16,代码来源:test_rackspace_uploader.py


示例14: test_rackspace_uploader_lookup_url_enable_cdn

    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)
开发者ID:PyBossa,项目名称:pybossa,代码行数:17,代码来源:test_rackspace_uploader.py


示例15: test_rackspace_uploader_init

    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
开发者ID:PyBossa,项目名称:pybossa,代码行数:19,代码来源:test_rackspace_uploader.py



注:本文中的pybossa.uploader.rackspace.RackspaceUploader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.get_user_signup_method函数代码示例发布时间:2022-05-25
下一篇:
Python local.LocalUploader类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap