Exemplo n.º 1
0
    def test_list_blobs(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            log.info(blob.name)

        assert len(blobs) == 2
Exemplo n.º 2
0
    def test_unregister_model_delete(self):
        blob = StorageBlobContext(**testconfig)

        blob.register_model(BlobOne())
        assert ('BlobOne' in [model['modelname'] for model in blob._modeldefinitions])

        blob.unregister_model(BlobOne(), delete_blob=True)
        assert (not 'BlobOne' in [model['modelname'] for model in blob._modeldefinitions])
Exemplo n.º 3
0
    def test_download_blobs(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            log.info(blob.name)
            bloboneinstance = container.download(BlobOne(name=blob.name))
            assert bloboneinstance.content != None  and bloboneinstance.exists()
Exemplo n.º 4
0
    def test_upload_text(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blob = BlobOne(**self.__class__.metadata)
        blob.fromtext('Test Blob')
        container.upload(blob)

        assert blob.user == 'bla' and blob.content == b'Test Blob' and blob.exists()
Exemplo n.º 5
0
    def test_error_file_replace(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            bloboneinstance = container.download(BlobOne(name=blob.name))
            with pytest.raises(AzureStorageWrapException):
                bloboneinstance.tofile(os.path.dirname(__file__))
Exemplo n.º 6
0
    def test_error_text_encoding(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            bloboneinstance = container.download(BlobOne(name=blob.name))
            bloboneinstance.properties.content_settings.content_encoding = None
            with pytest.raises(AzureStorageWrapException):
                blobtext = bloboneinstance.totext()
Exemplo n.º 7
0
    def test_delete_blob(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            log.info(blob.name)
            deleted = container.delete(BlobOne(name=blob.name))            
            assert deleted
            break
Exemplo n.º 8
0
    def test_blob_exists(self):

        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())
        blobs = container.list(BlobOne())
        
        for blob in blobs:
            exists = container.exists(BlobOne(name=blob.name))            
            assert exists
            break
Exemplo n.º 9
0
    def test_download_blobs_tofile(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            log.info(blob.name)
            bloboneinstance = container.download(BlobOne(name=blob.name))
            bloboneinstance.tofile(os.path.dirname(__file__),True)
            assert os.path.isfile(os.path.join(os.path.dirname(__file__), bloboneinstance.filename))
Exemplo n.º 10
0
    def test_upload_file(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        path_to_file = os.path.join(os.path.dirname(__file__), 'oliver.jpg')

        blob = BlobOne(**self.__class__.metadata)
        blob.fromfile(path_to_file)

        container.upload(blob)

        assert blob.user == 'bla' and blob.exists()
Exemplo n.º 11
0
    def test_download_blobs_totext(self):
        container = StorageBlobContext(**testconfig)
        container.register_model(BlobOne())

        blobs = container.list(BlobOne())
        for blob in blobs:
            log.info(blob.name)
            bloboneinstance = container.download(BlobOne(name=blob.name))
            if not bloboneinstance.properties.content_settings.content_encoding is None:
                blobtext = bloboneinstance.totext()
                assert blobtext == bloboneinstance.content.decode(bloboneinstance.properties.content_settings.content_encoding, 'ignore')
                break
Exemplo n.º 12
0
 def test_register_model(self):
     blob = StorageBlobContext(**testconfig)
     blob.register_model(BlobOne())
     assert 'BlobOne' in [model['modelname'] for model in blob._modeldefinitions]