示例#1
0
        def setup_method(self):
            self.app = App()

            self.app.bind('Application', application)
            self.app.bind('StorageConfig', storage)
            self.app.bind('UploadDiskDriver', UploadDiskDriver)
            self.app.bind('UploadManager', UploadManager(self.app))
            self.app.bind('Upload', UploadManager(self.app))
            self.app.bind('UploadS3Driver', UploadS3Driver)
示例#2
0
    def test_upload_file_for_s3():

        container = App()

        container.bind('Application', application)
        container.bind('StorageConfig', storage)
        container.bind('UploadDiskDriver', UploadDiskDriver)
        container.bind('UploadManager', UploadManager(container))
        container.bind('Upload', UploadManager(container))
        container.bind('UploadS3Driver', UploadS3Driver)

        img = ImageTest()

        assert container.make('Upload').driver('s3').store(img) is None
示例#3
0
    def test_upload_file_with_location_from_driver(self):
        """
        This test is responsible for checking if you upload a file correctly.
        """

        assert UploadManager(self.app).driver('disk').store(
            ImageMock(), 'disk.uploading')
示例#4
0
 def test_upload_manage_accept_files_error(self):
     """
     This test should return an error because it is an invalid extension.
     """
     with pytest.raises(FileTypeException):
         UploadManager(self.app).driver('s3').accept('png').store(
             ImageMock())
示例#5
0
 def test_upload_manager_validates_file_ext(self):
     """
     This test is responsible for checking if you upload
     a file correctly with a valid extension.
     """
     assert UploadManager(self.app).driver('disk').accept(
         'jpg', 'png').validate_extension('test.png')
示例#6
0
 def test_upload_manage_accept_files(self):
     """
     This test is responsible for checking if you upload
     a file correctly with a valid extension.
     """
     assert UploadManager(self.app).driver('disk').accept(
         'jpg', 'png').store(ImageMock())
示例#7
0
    def test_upload_file(self):
        """
        This test is responsible for checking if you upload a file correctly.
        """

        self.assertTrue(
            UploadManager(self.app).driver('disk').store(ImageMock()))
示例#8
0
    def test_upload_manager_raises_driver_not_found_error(self):
        self.app = App()
        self.app.bind('Test', object)
        self.app.bind('StorageConfig', storage)

        with pytest.raises(DriverNotFound):
            assert self.app.bind('UploadManager',
                                 UploadManager().load_container(self.app))
示例#9
0
 def setup_method(self):
     self.app = App()
     self.app.bind('Test', object)
     self.app.bind('StorageConfig', storage)
     self.app.bind('UploadDiskDriver', UploadDiskDriver)
     self.app.bind('Application', application)
     self.app.bind('UploadManager',
                   UploadManager().load_container(self.app))
示例#10
0
 def test_upload_manage_should_raise_exception_when_accept_all_extension_and_something_more(
         self):
     """
     This test should raise an error when use something together with '*' when allowing all extensions )
     """
     with self.assertRaises(ValueError):
         UploadManager(self.app).driver('disk').accept('*', 'png').store(
             ImageMock())
示例#11
0
def test_upload_file():
    """
    This test is responsible for checking if you upload a file correctly.
    """

    container = App()

    container.bind('Application', application)
    container.bind('StorageConfig', storage)
    container.bind('UploadDiskDriver', UploadDiskDriver)
    container.bind('UploadManager', UploadManager(container))
    container.bind('Upload', UploadManager(container))
    container.bind('UploadS3Driver', UploadS3Driver)

    img = ImageTest()

    assert UploadManager(container).driver('disk').store(img)
示例#12
0
def test_upload_manager_raises_driver_not_found_error():
    container = App()

    container.bind('Test', object)
    container.bind('StorageConfig', storage)

    with pytest.raises(DriverNotFound):
        assert container.bind('UploadManager',
                              UploadManager().load_container(container))
示例#13
0
def test_upload_store_prepend():
    container = App()

    container.bind('Application', application)
    container.bind('StorageConfig', storage)
    container.bind('UploadDiskDriver', UploadDiskDriver)
    container.bind('UploadManager', UploadManager(container))

    assert container.make('UploadManager').driver('disk').store_prepend(
        ImageTest(), 'hey') == 'uploads/heytest.jpg'
示例#14
0
def test_upload_manager_grabs_drivers():
    container = App()

    container.bind('Test', object)
    container.bind('StorageConfig', storage)
    container.bind('UploadDiskDriver', UploadDiskDriver)
    container.bind('Application', application)
    container.bind('UploadManager', UploadManager().load_container(container))

    assert isinstance(
        container.make('UploadManager').driver('disk'), UploadDiskDriver)
示例#15
0
    def test_upload_manage_accept_all_extensions(self):
        """
        This test should upload a file correctly by allowing all type files ( .accept('*') )
        """

        image = ImageMock()
        image.filename = 'file.pdf'

        print(image.filename)

        self.assertTrue(
            UploadManager(self.app).driver('disk').accept('*').store(image))
示例#16
0
def test_upload_manage_accept_files_error():
    """
    This test should return an error because it is an invalid extension.
    """

    container = App()

    container.bind('Application', application)
    container.bind('StorageConfig', storage)
    container.bind('UploadDiskDriver', UploadDiskDriver)

    img = ImageTest()
    with pytest.raises(FileTypeException):
        UploadManager(container).driver('disk').accept('png').store(img)
示例#17
0
def test_upload_manage_accept_files():
    """
    This test is responsible for checking if you upload
    a file correctly with a valid extension.
    """

    container = App()

    container.bind('Application', application)
    container.bind('StorageConfig', storage)
    container.bind('UploadDiskDriver', UploadDiskDriver)

    img = ImageTest()
    assert UploadManager(container).driver('disk').accept('jpg',
                                                          'png').store(img)
示例#18
0
 def register(self):
     self.app.bind('StorageConfig', storage)
     self.app.bind('UploadDiskDriver', UploadDiskDriver)
     self.app.bind('UploadS3Driver', UploadS3Driver)
     self.app.bind('UploadManager', UploadManager(self.app))
示例#19
0
 def boot(self, UploadManager, StorageConfig):
     self.app.bind('Upload', UploadManager.driver(StorageConfig.DRIVER))
示例#20
0
 def boot(self, UploadManager, StorageConfig, ViewClass):
     self.app.bind('Upload', UploadManager.driver(StorageConfig.DRIVER))
     ViewClass.share({
         'static': static,
     })