예제 #1
0
 def test_generated_key_is_str(self, monkeypatch):
     task = BlobStorageUpload(container="test")
     service = MagicMock()
     blob = MagicMock(BlockBlobService=MagicMock(return_value=service))
     monkeypatch.setattr("prefect.tasks.azure.blobstorage.azure.storage.blob", blob)
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with prefect.context(
             secrets=dict(AZ_CREDENTIALS={"ACCOUNT_NAME": "42", "ACCOUNT_KEY": "99"})
         ):
             task.run(data="")
     assert type(service.create_blob_from_text.call_args[1]["blob_name"]) == str
예제 #2
0
 def test_sas_token_creds_are_pulled_from_secret(self, monkeypatch):
     task = BlobStorageUpload(container="bob")
     service = MagicMock()
     blob = MagicMock(BlockBlobService=service)
     monkeypatch.setattr("prefect.tasks.azure.blobstorage.azure.storage.blob", blob)
     with set_temporary_config({"cloud.use_local_secrets": True}):
         with prefect.context(
             secrets=dict(AZ_CREDENTIALS={"ACCOUNT_NAME": "42", "SAS_TOKEN": "24"})
         ):
             task.run(data="")
     kwargs = service.call_args[1]
     assert kwargs == {"account_name": "42", "sas_token": "24", "account_key": None}
예제 #3
0
    def test_connection_string_creds_are_pulled_from_secret_and_runs(
            self, monkeypatch):
        task = BlobStorageUpload(container="bob")

        client = MagicMock(download_blob=MagicMock())
        service = MagicMock(get_blob_client=MagicMock(return_value=client))
        blob = MagicMock(BlockBlobService=MagicMock(service))
        monkeypatch.setattr(
            "prefect.tasks.azure.blobstorage.azure.storage.blob", blob)

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(AZ_CONNECTION_STRING="conn")):
                assert task.run(data="")
예제 #4
0
    def test_overwrite_passed_to_upload_blob(self, monkeypatch):
        task = BlobStorageUpload(container="bob", overwrite=True)

        data = "blob_data"
        upload_blob = MagicMock()
        blob_client = MagicMock(upload_blob=upload_blob)
        blob_service_client = MagicMock(get_blob_client=MagicMock(
            return_value=blob_client))
        from_connection_string = MagicMock(return_value=blob_service_client)
        blob = MagicMock(BlobServiceClient=MagicMock(
            from_connection_string=from_connection_string))
        monkeypatch.setattr(
            "prefect.tasks.azure.blobstorage.azure.storage.blob", blob)

        with set_temporary_config({"cloud.use_local_secrets": True}):
            with prefect.context(secrets=dict(AZ_CONNECTION_STRING="conn")):
                assert task.run(data=data)
                upload_blob.assert_called_once_with(data, overwrite=True)
예제 #5
0
 def test_raises_if_container_not_eventually_provided(self):
     task = BlobStorageUpload()
     with pytest.raises(ValueError, match="container"):
         task.run(data="")
예제 #6
0
 def test_initialization_passes_to_task_constructor(self):
     task = BlobStorageUpload(name="test", tags=["AZ"])
     assert task.name == "test"
     assert task.tags == {"AZ"}
예제 #7
0
 def test_initialization(self):
     task = BlobStorageUpload()
     assert task.azure_credentials_secret == "AZ_CONNECTION_STRING"
예제 #8
0
 def test_initialization(self):
     task = BlobStorageUpload()
     assert task.azure_credentials_secret == "AZ_CREDENTIALS"