From b969715be4162a425451420cc69d3af92e23ff02 Mon Sep 17 00:00:00 2001 From: fjetter Date: Wed, 22 Jan 2020 16:58:26 +0100 Subject: [PATCH] Workaround for missing has_key implementation --- .travis/start_minio.sh | 3 ++- simplekv/net/_azurestore_new.py | 10 +++++++++- tests/test_azure_store.py | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) mode change 100644 => 100755 .travis/start_minio.sh diff --git a/.travis/start_minio.sh b/.travis/start_minio.sh old mode 100644 new mode 100755 index 7cca504d..9e9dcfe7 --- a/.travis/start_minio.sh +++ b/.travis/start_minio.sh @@ -10,5 +10,6 @@ export MINIO_ACCESS_KEY=minio export MINIO_SECRET_KEY=miniostorage mkdir -p ~/s3 -~/minio version + +~/minio --version ~/minio server ~/s3 & diff --git a/simplekv/net/_azurestore_new.py b/simplekv/net/_azurestore_new.py index ac591a2e..a3752267 100644 --- a/simplekv/net/_azurestore_new.py +++ b/simplekv/net/_azurestore_new.py @@ -4,6 +4,7 @@ import hashlib import io from contextlib import contextmanager +from azure.core.exceptions import ResourceNotFoundError from .._compat import binary_type from .. import KeyValueStore @@ -95,7 +96,14 @@ def _get(self, key): return downloader.readall() def _has_key(self, key): - return self.blob_container_client.exists(key) + # https://github.com/Azure/azure-sdk-for-python/issues/9507 + blob_client = self.blob_container_client.get_blob_client(key) + try: + # One of the very few methods which do not mutate state + blob_client.get_blob_properties() + return True + except ResourceNotFoundError: + return False def iter_keys(self, prefix=None): blobs = self.blob_container_client.list_blobs(name_starts_with=prefix) diff --git a/tests/test_azure_store.py b/tests/test_azure_store.py index af9f4da7..81112003 100644 --- a/tests/test_azure_store.py +++ b/tests/test_azure_store.py @@ -66,6 +66,11 @@ def store(self): public=False) _delete_container(conn_string, container) + def test_exists(self, store): + assert "key" not in store + store.put("key", b"value") + assert "key" in store + class TestExtendedKeysAzureStorage(TestAzureStorage, ExtendedKeyspaceTests): @pytest.fixture