refactorig: Added abstract baseclass for StorageAdapter
This commit is contained in:
parent
26e0efb847
commit
f9ce6f80a9
@ -1,7 +1,22 @@
|
|||||||
class StorageAdapter:
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class StorageAdapter(ABC):
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self.__client = client
|
self.__client = client
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def put(self, bucket_name, object_name, data):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get(self, bucket_name, object_name):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_all(self, bucket_name):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def purge(self, bucket_name):
|
||||||
|
pass
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
|
from pyinfra.storage.adapter import StorageAdapter
|
||||||
from pyinfra.test.storage.client_mock import StorageClientMock
|
from pyinfra.test.storage.client_mock import StorageClientMock
|
||||||
|
|
||||||
|
|
||||||
class StorageAdapterMock:
|
class StorageAdapterMock(StorageAdapter):
|
||||||
def __init__(self, client: StorageClientMock):
|
def __init__(self, client: StorageClientMock):
|
||||||
assert isinstance(client, StorageClientMock)
|
assert isinstance(client, StorageClientMock)
|
||||||
self.__client = client
|
super().__init__(client=client)
|
||||||
|
self.__client = self._StorageAdapter__client
|
||||||
|
|
||||||
def put(self, bucket_name, object_name, data):
|
def put(self, bucket_name, object_name, data):
|
||||||
return self.__client.put(bucket_name, object_name, data)
|
return self.__client.put(bucket_name, object_name, data)
|
||||||
|
|||||||
@ -16,4 +16,3 @@ class StorageClientMock:
|
|||||||
|
|
||||||
def purge(self, bucket_name):
|
def purge(self, bucket_name):
|
||||||
self.__data[bucket_name] = {}
|
self.__data[bucket_name] = {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user