Compare commits
10
Commits
v0.2.2
...
f4280f15c1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4280f15c1 | ||
|
|
d9b9fa49a2 | ||
|
|
9d25f7c722 | ||
|
|
163581526d | ||
|
|
933c4ee7c5 | ||
|
|
2b0d98f84c | ||
|
|
729fa48505 | ||
|
|
fa011be862 | ||
|
|
2e9330949c | ||
|
|
3ab8da92fb |
@@ -7,11 +7,10 @@ Various python repository interfaces exposed as a python package.
|
|||||||
This package supports interacting with multiple different backends:
|
This package supports interacting with multiple different backends:
|
||||||
|
|
||||||
- Redis
|
- Redis
|
||||||
- Mongo
|
|
||||||
- MinIO
|
- MinIO
|
||||||
|
|
||||||
To add support for a specific backend install this package with one or more of these optional packages:
|
To add support for a specific backend install this package with one or more of these optional packages:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
uv add python-repositories[redis, mongo, minio]
|
uv add python-repositories[redis, minio]
|
||||||
```
|
```
|
||||||
|
|||||||
+2
-2
@@ -31,12 +31,12 @@ python-utils = { index = "gitea" }
|
|||||||
|
|
||||||
[[tool.uv.index]]
|
[[tool.uv.index]]
|
||||||
name = "threadripper-proxpi-cache"
|
name = "threadripper-proxpi-cache"
|
||||||
url = "http://10.0.0.2:5001/index/"
|
url = "https://proxpi.lille-vemmelund.dk/index/"
|
||||||
default = true
|
default = true
|
||||||
|
|
||||||
[[tool.uv.index]]
|
[[tool.uv.index]]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
url = "https://gitea.gt-proj.com/api/packages/brian/pypi/simple/"
|
url = "https://gitea.lille-vemmelund.dk/api/packages/brian/pypi/simple/"
|
||||||
explicit = true
|
explicit = true
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
|
|||||||
@@ -113,13 +113,20 @@ class MinioAdapter(
|
|||||||
self.logger.debug(res)
|
self.logger.debug(res)
|
||||||
return 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."""
|
"""Put an object into the Minio bucket."""
|
||||||
# Check input
|
# Check input
|
||||||
if not isinstance(object_name, str) or len(object_name) == 0:
|
if not isinstance(object_name, str) or len(object_name) == 0:
|
||||||
raise ValueError("object_name must be a non-empty string")
|
raise ValueError("object_name must be a non-empty string")
|
||||||
if not isinstance(data, BytesIO) or data.getbuffer().nbytes == 0:
|
if not isinstance(data, BytesIO) or data.getbuffer().nbytes == 0:
|
||||||
raise ValueError("data must be a non-empty BytesIO object")
|
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
|
# Check connection
|
||||||
if self._client is None or not self.is_connected:
|
if self._client is None or not self.is_connected:
|
||||||
raise ConnectionError("Not connected to Minio")
|
raise ConnectionError("Not connected to Minio")
|
||||||
@@ -134,6 +141,7 @@ class MinioAdapter(
|
|||||||
data=data,
|
data=data,
|
||||||
length=num_bytes,
|
length=num_bytes,
|
||||||
part_size=self.chunk_size,
|
part_size=self.chunk_size,
|
||||||
|
content_type=content_type,
|
||||||
)
|
)
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
f"Put object '{object_name}' into bucket '{self._bucket_name}'"
|
f"Put object '{object_name}' into bucket '{self._bucket_name}'"
|
||||||
|
|||||||
@@ -370,6 +370,20 @@ def test_should_raise_value_error_on_invalid_put_data(
|
|||||||
minio_adapter._put(object_name, data) # type: ignore
|
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(
|
def test_should_raise_connection_error_on_put_when_not_connected(
|
||||||
data: BytesIO,
|
data: BytesIO,
|
||||||
minio_adapter: MinioAdapter,
|
minio_adapter: MinioAdapter,
|
||||||
|
|||||||
Reference in New Issue
Block a user