Ejemplo n.º 1
0
class _AzureBlobBaseTestCase(object):
    def _get_credentials_dict(self):
        with open(self.credentials_filename, "r") as file_obj:
            return json.load(file_obj)

    def container_url(self, suffix=None):
        if suffix:
            return "https://{}.blob.core.windows.net/{}/{}".format(
                self.storage_account, self.container_name, suffix)
        return "https://{}.blob.core.windows.net/{}".format(
            self.storage_account, self.container_name)

    @pytest.fixture(autouse=True)
    def set_azure_client(self):
        config.load_system_configs()
        self.credentials_filename = config.get("azure_tests",
                                               "credentials_file")
        self.storage_account = config.get("azure_tests", "storage_account")
        self.container_name = config.get("azure_tests", "container_name")
        self.client = AzureBlobStorageClient(**self._get_credentials_dict())
        global ATTEMPTED_CONTAINER_CREATE
        if not ATTEMPTED_CONTAINER_CREATE:
            self.client.put_string(b"", self.container_name, "create_marker")
            ATTEMPTED_CONTAINER_CREATE = True
        yield self.client
Ejemplo n.º 2
0
 def set_azure_client(self):
     config.load_system_configs()
     self.credentials_filename = config.get("azure_tests",
                                            "credentials_file")
     self.storage_account = config.get("azure_tests", "storage_account")
     self.container_name = config.get("azure_tests", "container_name")
     self.client = AzureBlobStorageClient(**self._get_credentials_dict())
     global ATTEMPTED_CONTAINER_CREATE
     if not ATTEMPTED_CONTAINER_CREATE:
         self.client.put_string(b"", self.container_name, "create_marker")
         ATTEMPTED_CONTAINER_CREATE = True
     yield self.client
Ejemplo n.º 3
0
 def test_parse_path(self):
     account, container, blob = AzureBlobStorageClient._path_to_account_container_and_blob(
         "https://myaccount.blob.core.windows.net/mycontainer/folder1/folder2/myblob"
     )
     assert account == "myaccount"
     assert container == "mycontainer"
     assert blob == "folder1/folder2/myblob"
Ejemplo n.º 4
0
    def _dbfs_scheme_to_mount(self, path):
        if self.databricks_config.cloud_type != DatabricksCloud.azure:
            return path

        from dbnd_azure.fs.azure_blob import AzureBlobStorageClient

        storage_account, container_name, blob_name = AzureBlobStorageClient._path_to_account_container_and_blob(
            path)
        return "dbfs://%s" % (os.path.join(self.local_dbfs_mount, blob_name))
Ejemplo n.º 5
0
def build_azure_blob_fs_client():
    from dbnd_azure.fs.azure_blob import AzureBlobStorageClient

    return AzureBlobStorageClient(**get_azure_credentials())