From 9573c812a828b1612911290fd0e29f857d311124 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 23 Feb 2022 16:00:35 +0100 Subject: [PATCH] storage wrapper redesign WIP 2 (added test for dowloading all files from a bucket) --- pyinfra/storage/storage.py | 3 +++ pyinfra/test/storage/adapter_mock.py | 3 +++ pyinfra/test/storage/client_mock.py | 3 +++ pyinfra/test/unit_tests/storage_test.py | 12 ++++++++++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pyinfra/storage/storage.py b/pyinfra/storage/storage.py index ec882ee..6ff4003 100644 --- a/pyinfra/storage/storage.py +++ b/pyinfra/storage/storage.py @@ -8,6 +8,9 @@ class Storage: def get(self, bucket_name, object_name): return self.__adapter.get(bucket_name, object_name) + def get_all(self, bucket_name): + return self.__adapter.get_all(bucket_name) + diff --git a/pyinfra/test/storage/adapter_mock.py b/pyinfra/test/storage/adapter_mock.py index 164697b..a331070 100644 --- a/pyinfra/test/storage/adapter_mock.py +++ b/pyinfra/test/storage/adapter_mock.py @@ -11,3 +11,6 @@ class StorageAdapterMock: def get(self, bucket_name, object_name): return self.__client.get(bucket_name, object_name) + + def get_all(self, bucket_name): + return self.__client.get_all(bucket_name) diff --git a/pyinfra/test/storage/client_mock.py b/pyinfra/test/storage/client_mock.py index 3012d3f..7954300 100644 --- a/pyinfra/test/storage/client_mock.py +++ b/pyinfra/test/storage/client_mock.py @@ -10,3 +10,6 @@ class StorageClientMock: def get(self, bucket_name, object_name): return self.__data[bucket_name][object_name] + + def get_all(self, bucket_name): + return self.__data[bucket_name].values() diff --git a/pyinfra/test/unit_tests/storage_test.py b/pyinfra/test/unit_tests/storage_test.py index 0c7385b..1a80dfe 100644 --- a/pyinfra/test/unit_tests/storage_test.py +++ b/pyinfra/test/unit_tests/storage_test.py @@ -25,6 +25,14 @@ def bucket_name(): def test_getting_object_put_in_bucket_is_object(storage, bucket_name): with tempfile.SpooledTemporaryFile() as f: - storage.put(bucket_name, "testfile", f) - data_received = storage.get(bucket_name, "testfile") + storage.put(bucket_name, "file", f) + data_received = storage.get(bucket_name, "file") assert f == data_received + + +def test_getting_objects_put_in_bucket_are_objects(storage, bucket_name): + with tempfile.SpooledTemporaryFile() as f1, tempfile.SpooledTemporaryFile() as f2: + storage.put(bucket_name, "file1", f1) + storage.put(bucket_name, "file2", f2) + data_received = storage.get_all(bucket_name) + assert {f1, f2} == {*data_received}