Skip to content

Commit

Permalink
Merge pull request #20 from cottephi/main
Browse files Browse the repository at this point in the history
Important fixes
  • Loading branch information
oussjarrousse committed Apr 22, 2024
2 parents 0a32f7d + ba28868 commit e1bb055
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 14 additions & 8 deletions pytest_minio_mock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ class MockMinioObject:
Represents a mock object in Minio storage.
"""

def __init__(self, object_name):
def __init__(self, bucket_name, object_name):
self._bucket_name = bucket_name
self._object_name = object_name
self._versions = {}

@property
def bucket_name(self):
"""Get the name of the bucket"""
return self._bucket_name

@property
def object_name(self):
"""Get the name of the object stored at initialization"""
Expand Down Expand Up @@ -162,12 +168,12 @@ def get_latest(self):
return obj
raise RuntimeError("Implemnetation Error")

def put_object_version(self, version_id, obj):
def put_object_version(self, version_id, obj: MockMinioObjectVersion):
"""
Inserts a object version in the _versions map.
Inserts an object version in the _versions map.
"""
self.reset_latest()
obj.latest = True
obj.is_latest = True
self._versions[version_id] = obj

def put_object(
Expand Down Expand Up @@ -223,13 +229,13 @@ def get_object(self, version_id, versioning: VersioningConfig):
if version_id and version_id != "null" and not validators.uuid(version_id):
raise S3Error(
message="Invalid version id specified",
resource=f"/{self.bucket_name}/{object_name}",
resource=f"/{self.bucket_name}/{self.object_name}",
request_id=None,
host_id=None,
response="mocked_response",
code=422,
bucket_name=self.bucket_name,
object_name=object_name,
object_name=self.object_name,
)

# If version == None, give version_id a value
Expand Down Expand Up @@ -318,7 +324,7 @@ def remove_object(self, version_id, versioning: VersioningConfig):
if versioning.status == ENABLED:
if version_id:
if version_id not in self.versions:
# version_id does not exist
# version_id does not exist,
# nothing to do
return
else:
Expand Down Expand Up @@ -420,7 +426,7 @@ def put_object(
newly added object
"""
if object_name not in self.objects:
self.objects[object_name] = MockMinioObject(object_name)
self.objects[object_name] = MockMinioObject(self.bucket_name, object_name)

obj = self.objects[object_name].put_object(
object_name=object_name,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_minio_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class TestsMockMinioObject:
@pytest.mark.UNIT
def test_mock_minio_object_init(self):
mock_minio_object = MockMinioObject("test-object")
mock_minio_object = MockMinioObject("test-bucket", "test-object")
assert mock_minio_object.versions == {}


Expand Down Expand Up @@ -115,6 +115,8 @@ def test_putting_objects_with_versionning_enabled(minio_mock):
# check that versions are stored correctly and retrieved correctly
objects = list(client.list_objects(bucket_name, object_name, include_version=True))
assert len(objects) == 2
with pytest.raises(S3Error, match="Invalid version"):
client.get_object(bucket_name, object_name, version_id="wrong")


@pytest.mark.API
Expand Down

0 comments on commit e1bb055

Please sign in to comment.