datadouble-s3 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datadouble_s3-0.0.3/.gitignore +21 -0
- datadouble_s3-0.0.3/LICENSE +21 -0
- datadouble_s3-0.0.3/PKG-INFO +42 -0
- datadouble_s3-0.0.3/README.md +21 -0
- datadouble_s3-0.0.3/pyproject.toml +38 -0
- datadouble_s3-0.0.3/src/datadouble_s3/__init__.py +151 -0
- datadouble_s3-0.0.3/src/datadouble_s3/py.typed +0 -0
- datadouble_s3-0.0.3/tests/test_s3.py +135 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.py[cod]
|
|
6
|
+
.venv/
|
|
7
|
+
.env
|
|
8
|
+
.coverage
|
|
9
|
+
.coverage.*
|
|
10
|
+
coverage.xml
|
|
11
|
+
.reports/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
.ruff_cache/
|
|
15
|
+
dist/
|
|
16
|
+
site/
|
|
17
|
+
.cache/
|
|
18
|
+
|
|
19
|
+
# The default work directory of `datadouble run`.
|
|
20
|
+
.datadouble/
|
|
21
|
+
node_modules/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026- Tight Line LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datadouble-s3
|
|
3
|
+
Version: 0.0.3
|
|
4
|
+
Summary: S3 storage adapter for Datadouble
|
|
5
|
+
Project-URL: Homepage, https://datadouble.tightlinesoftware.com/
|
|
6
|
+
Project-URL: Source, https://github.com/datadouble/datadouble
|
|
7
|
+
Author: Tight Line LLC
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Classifier: Topic :: System :: Archiving
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Requires-Dist: boto3>=1.44.13
|
|
19
|
+
Requires-Dist: datadouble
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# datadouble-s3
|
|
23
|
+
|
|
24
|
+
The S3 storage adapter for [Datadouble](https://datadouble.tightlinesoftware.com/):
|
|
25
|
+
golden images and their image summaries in an S3 bucket, or any service with
|
|
26
|
+
an S3-compatible API.
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
store:
|
|
30
|
+
- s3:
|
|
31
|
+
bucket: golden-images
|
|
32
|
+
prefix: shop # optional
|
|
33
|
+
region: us-east-1 # optional
|
|
34
|
+
endpoint_url: https://s3.internal.example # optional, for S3-compatible services
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Credentials come from the usual AWS sources (environment, shared files, an
|
|
38
|
+
instance or workload role); they never appear in the spec.
|
|
39
|
+
|
|
40
|
+
`prefix` is a key prefix inside the bucket, not a directory. Even a prefix
|
|
41
|
+
that starts with `/` is never mounted into the jobs `ci init` writes
|
|
42
|
+
([which settings become mounts](../../docs/ci-cd.md#which-settings-become-mounts)).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# datadouble-s3
|
|
2
|
+
|
|
3
|
+
The S3 storage adapter for [Datadouble](https://datadouble.tightlinesoftware.com/):
|
|
4
|
+
golden images and their image summaries in an S3 bucket, or any service with
|
|
5
|
+
an S3-compatible API.
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
store:
|
|
9
|
+
- s3:
|
|
10
|
+
bucket: golden-images
|
|
11
|
+
prefix: shop # optional
|
|
12
|
+
region: us-east-1 # optional
|
|
13
|
+
endpoint_url: https://s3.internal.example # optional, for S3-compatible services
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Credentials come from the usual AWS sources (environment, shared files, an
|
|
17
|
+
instance or workload role); they never appear in the spec.
|
|
18
|
+
|
|
19
|
+
`prefix` is a key prefix inside the bucket, not a directory. Even a prefix
|
|
20
|
+
that starts with `/` is never mounted into the jobs `ci init` writes
|
|
21
|
+
([which settings become mounts](../../docs/ci-cd.md#which-settings-become-mounts)).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "datadouble-s3"
|
|
6
|
+
# All packages share one version until 1.0 (decision 38); scripts/make_tag.py
|
|
7
|
+
# sets it at release time.
|
|
8
|
+
version = "0.0.3"
|
|
9
|
+
description = "S3 storage adapter for Datadouble"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Tight Line LLC" }]
|
|
14
|
+
requires-python = ">=3.13"
|
|
15
|
+
dependencies = ["datadouble", "boto3>=1.44.13"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Programming Language :: Python :: 3.15",
|
|
22
|
+
"Topic :: System :: Archiving",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://datadouble.tightlinesoftware.com/"
|
|
28
|
+
Source = "https://github.com/datadouble/datadouble"
|
|
29
|
+
|
|
30
|
+
[project.entry-points."datadouble.stores"]
|
|
31
|
+
s3 = "datadouble_s3:s3_store"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["hatchling>=1.33.0"]
|
|
35
|
+
build-backend = "hatchling.build"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/datadouble_s3"]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""The S3 storage adapter for Datadouble.
|
|
5
|
+
|
|
6
|
+
Spec settings::
|
|
7
|
+
|
|
8
|
+
store:
|
|
9
|
+
- s3:
|
|
10
|
+
bucket: golden-images
|
|
11
|
+
prefix: shop # optional
|
|
12
|
+
region: us-east-1 # optional
|
|
13
|
+
endpoint_url: https://s3.internal.example # optional, S3-compatible services
|
|
14
|
+
|
|
15
|
+
Credentials come from the usual AWS sources and never appear in the spec.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from collections.abc import Mapping
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
21
|
+
|
|
22
|
+
import boto3
|
|
23
|
+
from botocore.config import Config
|
|
24
|
+
from botocore.exceptions import BotoCoreError, ClientError
|
|
25
|
+
from pydantic import BaseModel, ConfigDict, Field, JsonValue
|
|
26
|
+
|
|
27
|
+
from datadouble.settings import parse_settings, remote
|
|
28
|
+
from datadouble.storage import Store, StoreError, check_key
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
# Typing stubs, installed only for development; the runtime image lacks them.
|
|
32
|
+
from mypy_boto3_s3 import S3Client
|
|
33
|
+
|
|
34
|
+
_MISSING = frozenset({"NoSuchKey", "404", "NotFound"})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class S3Settings(BaseModel):
|
|
38
|
+
"""The settings of one ``s3`` store."""
|
|
39
|
+
|
|
40
|
+
model_config = ConfigDict(strict=True, frozen=True, extra="forbid")
|
|
41
|
+
|
|
42
|
+
bucket: str = Field(min_length=3, max_length=63)
|
|
43
|
+
prefix: str = ""
|
|
44
|
+
region: str | None = None
|
|
45
|
+
endpoint_url: str | None = None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _failure(error: Exception, action: str) -> StoreError:
|
|
49
|
+
"""A store error naming the S3 error code, not the request or credentials."""
|
|
50
|
+
if isinstance(error, ClientError):
|
|
51
|
+
code = error.response.get("Error", {}).get("Code", "unknown")
|
|
52
|
+
return StoreError(f"{action} failed: S3 error {code}")
|
|
53
|
+
return StoreError(f"{action} failed: {type(error).__name__}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _code(error: ClientError) -> str:
|
|
57
|
+
return str(error.response.get("Error", {}).get("Code", ""))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class S3Store:
|
|
61
|
+
"""Images under one bucket and key prefix."""
|
|
62
|
+
|
|
63
|
+
def __init__(self, settings: S3Settings, client: "S3Client") -> None:
|
|
64
|
+
"""Use ``client`` for every request."""
|
|
65
|
+
self.settings = settings
|
|
66
|
+
self.client = client
|
|
67
|
+
self.prefix = settings.prefix.strip("/")
|
|
68
|
+
|
|
69
|
+
def _key(self, key: str) -> str:
|
|
70
|
+
check_key(key)
|
|
71
|
+
return f"{self.prefix}/{key}" if self.prefix else key
|
|
72
|
+
|
|
73
|
+
def describe(self) -> str:
|
|
74
|
+
"""``s3://bucket/prefix``."""
|
|
75
|
+
location = f"s3://{self.settings.bucket}"
|
|
76
|
+
return f"{location}/{self.prefix}" if self.prefix else location
|
|
77
|
+
|
|
78
|
+
def put_file(self, key: str, source: Path) -> None:
|
|
79
|
+
"""Upload a file; large files go up in parts, and only appear when complete."""
|
|
80
|
+
try:
|
|
81
|
+
self.client.upload_file(str(source), self.settings.bucket, self._key(key))
|
|
82
|
+
except (BotoCoreError, ClientError) as error:
|
|
83
|
+
raise _failure(error, f"uploading {key}") from None
|
|
84
|
+
|
|
85
|
+
def put_bytes(self, key: str, data: bytes) -> None:
|
|
86
|
+
"""Write a small object."""
|
|
87
|
+
try:
|
|
88
|
+
self.client.put_object(Bucket=self.settings.bucket, Key=self._key(key), Body=data)
|
|
89
|
+
except (BotoCoreError, ClientError) as error:
|
|
90
|
+
raise _failure(error, f"writing {key}") from None
|
|
91
|
+
|
|
92
|
+
def get_bytes(self, key: str) -> bytes | None:
|
|
93
|
+
"""Read a small object, or None if it does not exist."""
|
|
94
|
+
try:
|
|
95
|
+
response = self.client.get_object(Bucket=self.settings.bucket, Key=self._key(key))
|
|
96
|
+
except ClientError as error:
|
|
97
|
+
if _code(error) in _MISSING:
|
|
98
|
+
return None
|
|
99
|
+
raise _failure(error, f"reading {key}") from None
|
|
100
|
+
except BotoCoreError as error:
|
|
101
|
+
raise _failure(error, f"reading {key}") from None
|
|
102
|
+
return response["Body"].read()
|
|
103
|
+
|
|
104
|
+
def get_file(self, key: str, destination: Path) -> bool:
|
|
105
|
+
"""Download an object; False if it does not exist."""
|
|
106
|
+
try:
|
|
107
|
+
self.client.download_file(self.settings.bucket, self._key(key), str(destination))
|
|
108
|
+
except ClientError as error:
|
|
109
|
+
if _code(error) in _MISSING:
|
|
110
|
+
return False
|
|
111
|
+
raise _failure(error, f"downloading {key}") from None
|
|
112
|
+
except BotoCoreError as error:
|
|
113
|
+
raise _failure(error, f"downloading {key}") from None
|
|
114
|
+
return True
|
|
115
|
+
|
|
116
|
+
def delete(self, key: str) -> None:
|
|
117
|
+
"""Remove an object; S3 does not mind if it does not exist."""
|
|
118
|
+
try:
|
|
119
|
+
self.client.delete_object(Bucket=self.settings.bucket, Key=self._key(key))
|
|
120
|
+
except (BotoCoreError, ClientError) as error:
|
|
121
|
+
raise _failure(error, f"deleting {key}") from None
|
|
122
|
+
|
|
123
|
+
def list(self, prefix: str) -> list[str]:
|
|
124
|
+
"""Keys starting with ``prefix``, relative to the store's own prefix."""
|
|
125
|
+
root = f"{self.prefix}/" if self.prefix else ""
|
|
126
|
+
keys: list[str] = []
|
|
127
|
+
try:
|
|
128
|
+
for page in self.client.get_paginator("list_objects_v2").paginate(
|
|
129
|
+
Bucket=self.settings.bucket, Prefix=root + prefix
|
|
130
|
+
):
|
|
131
|
+
keys.extend(item.get("Key", "")[len(root) :] for item in page.get("Contents", []))
|
|
132
|
+
except (BotoCoreError, ClientError) as error:
|
|
133
|
+
raise _failure(error, f"listing {prefix or '/'}") from None
|
|
134
|
+
return sorted(keys)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@remote("prefix")
|
|
138
|
+
def s3_store(settings: Mapping[str, JsonValue]) -> Store:
|
|
139
|
+
"""The entry point named in ``datadouble.stores``.
|
|
140
|
+
|
|
141
|
+
``prefix`` is a key prefix in the bucket, never a path on the job's machine.
|
|
142
|
+
"""
|
|
143
|
+
parsed = parse_settings(S3Settings, settings, "s3 store")
|
|
144
|
+
# boto3-stubs overloads client() for every AWS service; only S3's stubs are installed.
|
|
145
|
+
client: S3Client = boto3.client( # pyright: ignore[reportUnknownMemberType] - see above
|
|
146
|
+
"s3",
|
|
147
|
+
region_name=parsed.region,
|
|
148
|
+
endpoint_url=parsed.endpoint_url,
|
|
149
|
+
config=Config(s3={"addressing_style": "path"} if parsed.endpoint_url else {}),
|
|
150
|
+
)
|
|
151
|
+
return S3Store(parsed, client)
|
|
File without changes
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Copyright (c) 2026- Tight Line LLC
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"""The S3 store: error handling against a stubbed client, behavior against SeaweedFS."""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import uuid
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import boto3
|
|
11
|
+
import pytest
|
|
12
|
+
from botocore.config import Config
|
|
13
|
+
from botocore.stub import Stubber
|
|
14
|
+
from mypy_boto3_s3 import S3Client
|
|
15
|
+
|
|
16
|
+
from datadouble.registry import installed
|
|
17
|
+
from datadouble.settings import SettingsError, remote_keys
|
|
18
|
+
from datadouble.storage import StoreError
|
|
19
|
+
from datadouble_s3 import S3Settings, S3Store, s3_store
|
|
20
|
+
|
|
21
|
+
ENDPOINT = "DATADOUBLE_TEST_S3_ENDPOINT"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def offline_client() -> S3Client:
|
|
25
|
+
client: S3Client = boto3.client( # pyright: ignore[reportUnknownMemberType] - only S3 stubs installed
|
|
26
|
+
"s3",
|
|
27
|
+
region_name="us-east-1",
|
|
28
|
+
aws_access_key_id="test",
|
|
29
|
+
aws_secret_access_key="test", # noqa: S106 - a stub needs some credentials
|
|
30
|
+
)
|
|
31
|
+
return client
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_settings() -> None:
|
|
35
|
+
store = s3_store({"bucket": "images", "prefix": "/shop/", "endpoint_url": "http://x:1"})
|
|
36
|
+
assert store.describe() == "s3://images/shop"
|
|
37
|
+
assert s3_store({"bucket": "images"}).describe() == "s3://images"
|
|
38
|
+
with pytest.raises(SettingsError, match="s3 store settings are invalid: bucket"):
|
|
39
|
+
s3_store({"bucket": "x"})
|
|
40
|
+
assert "s3" in installed().stores
|
|
41
|
+
# The prefix is a key in the bucket, so `ci init` never mounts it.
|
|
42
|
+
assert installed().remote_settings().stores["s3"] == (("prefix",),)
|
|
43
|
+
assert remote_keys(s3_store) == (("prefix",),)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_errors_name_the_code_not_the_request(tmp_path: Path) -> None:
|
|
47
|
+
client = offline_client()
|
|
48
|
+
store = S3Store(S3Settings(bucket="images"), client)
|
|
49
|
+
source = tmp_path / "file"
|
|
50
|
+
source.write_bytes(b"x")
|
|
51
|
+
with Stubber(client) as stub:
|
|
52
|
+
stub.add_client_error("put_object", service_error_code="AccessDenied")
|
|
53
|
+
stub.add_client_error("get_object", service_error_code="AccessDenied")
|
|
54
|
+
stub.add_client_error("get_object", service_error_code="NoSuchKey")
|
|
55
|
+
stub.add_client_error("list_objects_v2", service_error_code="NoSuchBucket")
|
|
56
|
+
with pytest.raises(StoreError, match="writing a/b failed: S3 error AccessDenied"):
|
|
57
|
+
store.put_bytes("a/b", b"x")
|
|
58
|
+
with pytest.raises(StoreError, match="reading a/b failed: S3 error AccessDenied"):
|
|
59
|
+
store.get_bytes("a/b")
|
|
60
|
+
assert store.get_bytes("a/b") is None
|
|
61
|
+
stub.add_client_error("head_object", service_error_code="403", http_status_code=403)
|
|
62
|
+
stub.add_client_error("head_object", service_error_code="404", http_status_code=404)
|
|
63
|
+
stub.add_client_error("delete_object", service_error_code="AccessDenied")
|
|
64
|
+
with pytest.raises(StoreError, match="listing / failed: S3 error NoSuchBucket"):
|
|
65
|
+
store.list("")
|
|
66
|
+
with pytest.raises(StoreError, match="downloading a/b failed: S3 error 403"):
|
|
67
|
+
store.get_file("a/b", tmp_path / "out")
|
|
68
|
+
assert not store.get_file("a/b", tmp_path / "out")
|
|
69
|
+
with pytest.raises(StoreError, match="deleting a/b failed: S3 error AccessDenied"):
|
|
70
|
+
store.delete("a/b")
|
|
71
|
+
with pytest.raises(StoreError, match="not a valid store key"):
|
|
72
|
+
store.put_bytes("../escape", b"x")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_connection_failures(tmp_path: Path) -> None:
|
|
76
|
+
client: S3Client = boto3.client( # pyright: ignore[reportUnknownMemberType] - only S3 stubs installed
|
|
77
|
+
"s3",
|
|
78
|
+
region_name="us-east-1",
|
|
79
|
+
endpoint_url="http://127.0.0.1:9",
|
|
80
|
+
aws_access_key_id="test",
|
|
81
|
+
aws_secret_access_key="test", # noqa: S106 - a stub needs some credentials
|
|
82
|
+
config=Config(retries={"max_attempts": 1}, connect_timeout=1),
|
|
83
|
+
)
|
|
84
|
+
store = S3Store(S3Settings(bucket="images"), client)
|
|
85
|
+
source = tmp_path / "file"
|
|
86
|
+
source.write_bytes(b"x")
|
|
87
|
+
for action, call in (
|
|
88
|
+
("uploading", lambda: store.put_file("a", source)),
|
|
89
|
+
("writing", lambda: store.put_bytes("a", b"x")),
|
|
90
|
+
("reading", lambda: store.get_bytes("a")),
|
|
91
|
+
("downloading", lambda: store.get_file("a", tmp_path / "out")),
|
|
92
|
+
("listing", lambda: store.list("a")),
|
|
93
|
+
):
|
|
94
|
+
with pytest.raises(StoreError, match=f"{action} a failed: EndpointConnectionError"):
|
|
95
|
+
call()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@pytest.fixture
|
|
99
|
+
def bucket() -> S3Store:
|
|
100
|
+
endpoint = os.environ.get(ENDPOINT)
|
|
101
|
+
if not endpoint:
|
|
102
|
+
pytest.skip(f"{ENDPOINT} is not set; run in the Compose default group")
|
|
103
|
+
name = f"dd-{uuid.uuid4().hex[:12]}"
|
|
104
|
+
store = s3_store({"bucket": name, "prefix": "images", "endpoint_url": endpoint})
|
|
105
|
+
assert isinstance(store, S3Store)
|
|
106
|
+
store.client.create_bucket(Bucket=name)
|
|
107
|
+
return store
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@pytest.mark.integration
|
|
111
|
+
def test_round_trips(bucket: S3Store, tmp_path: Path) -> None:
|
|
112
|
+
big = tmp_path / "big"
|
|
113
|
+
big.write_bytes(os.urandom(9 * 1024 * 1024))
|
|
114
|
+
bucket.put_file("shop/all/a.tar.gz", big)
|
|
115
|
+
bucket.put_bytes("shop/all/a.summary.json", b"{}")
|
|
116
|
+
assert bucket.get_bytes("shop/all/a.summary.json") == b"{}"
|
|
117
|
+
assert bucket.get_bytes("shop/all/missing") is None
|
|
118
|
+
assert bucket.get_file("shop/all/a.tar.gz", tmp_path / "copy")
|
|
119
|
+
assert (tmp_path / "copy").read_bytes() == big.read_bytes()
|
|
120
|
+
assert not bucket.get_file("shop/all/missing", tmp_path / "none")
|
|
121
|
+
assert bucket.list("shop/") == ["shop/all/a.summary.json", "shop/all/a.tar.gz"]
|
|
122
|
+
assert bucket.list("") == ["shop/all/a.summary.json", "shop/all/a.tar.gz"]
|
|
123
|
+
assert bucket.list("other/") == []
|
|
124
|
+
bucket.delete("shop/all/a.summary.json")
|
|
125
|
+
bucket.delete("shop/all/never-there")
|
|
126
|
+
assert bucket.list("shop/") == ["shop/all/a.tar.gz"]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@pytest.mark.integration
|
|
130
|
+
def test_many_keys_page(bucket: S3Store) -> None:
|
|
131
|
+
for number in range(1005):
|
|
132
|
+
bucket.put_bytes(f"many/{number:04d}", b"")
|
|
133
|
+
keys = bucket.list("many/")
|
|
134
|
+
assert len(keys) == 1005
|
|
135
|
+
assert keys[0] == "many/0000"
|