Commit 706d6f53 authored by Christophe Lallement's avatar Christophe Lallement
Browse files

fix stop catching azure exceptions

parent e208d1d4
......@@ -10,12 +10,6 @@ from azure.core import exceptions as AzureExceptions
from osdu.core.api.storage.blob_storage_base import BlobStorageBase
from osdu.core.api.storage.blob import Blob
from osdu.core.api.storage.tenant import Tenant
from osdu.core.api.storage.exceptions import (
with_blobstorage_exception,
AuthenticationException,
ResourceNotFoundException,
ResourceExistsException,
PreconditionFailedException)
from osdu_az.partition.partition_service import PartitionService
_LOGGER = logging.getLogger(__name__)
......@@ -35,13 +29,7 @@ class AzureAioBlobStorage(BlobStorageBase):
Credentials = None
ExceptionMapping = {
AzureExceptions.ClientAuthenticationError: AuthenticationException,
AzureExceptions.ResourceNotFoundError: ResourceNotFoundException,
AzureExceptions.ResourceExistsError: ResourceExistsException,
AzureExceptions.ResourceModifiedError: PreconditionFailedException,
AzureExceptions.ResourceNotModifiedError: PreconditionFailedException,
}
def _build_url(self, storage_account: str):
return f'https://{storage_account}.blob.core.windows.net'
......
......@@ -4,6 +4,8 @@ from io import BytesIO
import uuid
from mock import patch
from azure.core import exceptions as AzureExceptions
from osdu.core.api.storage.tenant import Tenant
from osdu.core.api.storage.exceptions import *
......@@ -59,7 +61,7 @@ async def test_overwrite_with_condition(az_client: AzureAioBlobStorage, test_ten
blob_name = 'testing_data/' + str(uuid.uuid4())
await az_client.upload(test_tenant, blob_name, b'1111')
with pytest.raises(ResourceExistsException):
with pytest.raises(AzureExceptions.ResourceExistsError):
await az_client.upload(test_tenant, blob_name, b'1111', overwrite=False)
# update no condition
......@@ -72,7 +74,7 @@ async def test_overwrite_with_condition(az_client: AzureAioBlobStorage, test_ten
assert await az_client.download(test_tenant, blob_name) == b'1113'
# should fail update if_match not satisfied
with pytest.raises(PreconditionFailedException):
with pytest.raises(AzureExceptions.ResourceModifiedError):
await az_client.upload(test_tenant, blob_name, b'1114', if_match=etag_1112)
# success update if_not_match
......@@ -81,7 +83,7 @@ async def test_overwrite_with_condition(az_client: AzureAioBlobStorage, test_ten
# should fail update if_not_match not satisfied
etag_1115 = (await az_client.download_metadata(test_tenant, blob_name)).etag
with pytest.raises(PreconditionFailedException):
with pytest.raises(AzureExceptions.ResourceModifiedError):
await az_client.upload(test_tenant, blob_name, b'1116', if_not_match=etag_1115)
......@@ -114,7 +116,7 @@ async def test_concurrent_update_only_one_should_succeed(az_client: AzureAioBlob
async def test_download_not_existing_blob_should_throw(az_client: AzureAioBlobStorage, test_tenant):
# here we just ensure it does not silently fail and throw something for now (to be updated when proper exceptions
# will be defined in the core lib)
with pytest.raises(ResourceNotFoundException):
with pytest.raises(AzureExceptions.ResourceNotFoundError):
# given a not existing blob
blob_name = 'testing_data/' + str(uuid.uuid4())
......@@ -124,7 +126,7 @@ async def test_download_not_existing_blob_should_throw(az_client: AzureAioBlobSt
@pytest.mark.asyncio
async def test_invalid_storage_container(az_client: AzureAioBlobStorage):
with pytest.raises(ResourceNotFoundException):
with pytest.raises(AzureExceptions.ResourceNotFoundError):
tenant = Tenant(project_id=Config.storage_account, bucket_name='not_existing_container', data_partition_id='local')
await az_client.upload(tenant, 'blob_name', 'input_data')
......@@ -156,6 +158,6 @@ async def test_delete(az_client: AzureAioBlobStorage, test_tenant):
await az_client.download(test_tenant, blob_name)
await az_client.delete(test_tenant, blob_name)
with pytest.raises(ResourceNotFoundException):
with pytest.raises(AzureExceptions.ResourceNotFoundError):
await az_client.download(test_tenant, blob_name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment