From 3ab8da92fbd3fc5c5f75abee9c81500219705a1c Mon Sep 17 00:00:00 2001 From: Brian Bjarke Jensen Date: Thu, 18 Sep 2025 19:34:05 +0200 Subject: [PATCH] added support for content type when putting object in minio --- python_repositories/adapters/minio_adapter.py | 5 ++++- tests/integration/minio_adapter_test.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/python_repositories/adapters/minio_adapter.py b/python_repositories/adapters/minio_adapter.py index 0c67290..b91073b 100644 --- a/python_repositories/adapters/minio_adapter.py +++ b/python_repositories/adapters/minio_adapter.py @@ -113,13 +113,15 @@ class MinioAdapter( self.logger.debug(res) return res - def _put(self, object_name: str, data: BytesIO) -> None: + def _put(self, object_name: str, data: BytesIO, content_type: str = "application/octet-stream") -> None: """Put an object into the Minio bucket.""" # Check input if not isinstance(object_name, str) or len(object_name) == 0: raise ValueError("object_name must be a non-empty string") if not isinstance(data, BytesIO) or data.getbuffer().nbytes == 0: raise ValueError("data must be a non-empty BytesIO object") + if not isinstance(content_type, str) or len(content_type) == 0: + raise ValueError("content_type must be a non-empty string") # Check connection if self._client is None or not self.is_connected: raise ConnectionError("Not connected to Minio") @@ -134,6 +136,7 @@ class MinioAdapter( data=data, length=num_bytes, part_size=self.chunk_size, + content_type=content_type, ) self.logger.debug( f"Put object '{object_name}' into bucket '{self._bucket_name}'" diff --git a/tests/integration/minio_adapter_test.py b/tests/integration/minio_adapter_test.py index cc5da13..95ad882 100644 --- a/tests/integration/minio_adapter_test.py +++ b/tests/integration/minio_adapter_test.py @@ -370,6 +370,20 @@ def test_should_raise_value_error_on_invalid_put_data( minio_adapter._put(object_name, data) # type: ignore +def test_should_raise_value_error_on_invalid_put_content_type( + data: BytesIO, + minio_adapter: MinioAdapter, +) -> None: + """Test that the MinioAdapter raises ValueError when putting with an invalid content type.""" + # Arrange + object_name = "valid_object_name" + invalid_content_types = ["", 123, None] + # Act & Assert + for content_type in invalid_content_types: + with pytest.raises(ValueError): + minio_adapter._put(object_name, data, content_type) # type: ignore + + def test_should_raise_connection_error_on_put_when_not_connected( data: BytesIO, minio_adapter: MinioAdapter,