Skip to content

Commit f926fb5

Browse files
committed
Update S3 tests for date-based folder structure
Update tests to use keyword arguments for s3_path parameter and add tests for the new created_at date folder functionality.
1 parent a01a6b7 commit f926fb5

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

tests/storage/test_s3.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,36 +186,51 @@ def test_create_client_with_various_aws_regions(self):
186186
class TestBuildS3Key:
187187
"""Tests for the _build_s3_key helper function."""
188188

189-
def test_build_key_without_prefix(self):
190-
"""Test key building without s3_path prefix."""
189+
def test_build_key_without_prefix_or_date(self):
190+
"""Test key building without s3_path prefix or created_at."""
191191
key = _build_s3_key("test-uuid")
192192
assert key == "test-uuid.vcon"
193193

194-
def test_build_key_with_prefix(self):
195-
"""Test key building with s3_path prefix."""
196-
key = _build_s3_key("test-uuid", "vcons")
194+
def test_build_key_with_prefix_only(self):
195+
"""Test key building with s3_path prefix but no created_at."""
196+
key = _build_s3_key("test-uuid", s3_path="vcons")
197197
assert key == "vcons/test-uuid.vcon"
198198

199199
def test_build_key_with_trailing_slash_prefix(self):
200200
"""Test key building with trailing slash in prefix."""
201-
key = _build_s3_key("test-uuid", "vcons/")
201+
key = _build_s3_key("test-uuid", s3_path="vcons/")
202202
assert key == "vcons/test-uuid.vcon"
203203

204204
def test_build_key_with_none_prefix(self):
205205
"""Test key building with None prefix."""
206-
key = _build_s3_key("test-uuid", None)
206+
key = _build_s3_key("test-uuid", s3_path=None)
207207
assert key == "test-uuid.vcon"
208208

209209
def test_build_key_with_empty_prefix(self):
210210
"""Test key building with empty string prefix."""
211-
key = _build_s3_key("test-uuid", "")
211+
key = _build_s3_key("test-uuid", s3_path="")
212212
assert key == "test-uuid.vcon"
213213

214214
def test_build_key_with_nested_prefix(self):
215215
"""Test key building with nested prefix."""
216-
key = _build_s3_key("test-uuid", "data/vcons/archive")
216+
key = _build_s3_key("test-uuid", s3_path="data/vcons/archive")
217217
assert key == "data/vcons/archive/test-uuid.vcon"
218218

219+
def test_build_key_with_created_at(self):
220+
"""Test key building with created_at generates date folder."""
221+
key = _build_s3_key("test-uuid", created_at="2025-12-10T15:30:00Z")
222+
assert key == "2025/12/10/test-uuid.vcon"
223+
224+
def test_build_key_with_created_at_and_prefix(self):
225+
"""Test key building with both created_at and s3_path."""
226+
key = _build_s3_key("test-uuid", created_at="2025-12-10T15:30:00Z", s3_path="vcons")
227+
assert key == "vcons/2025/12/10/test-uuid.vcon"
228+
229+
def test_build_key_with_created_at_and_nested_prefix(self):
230+
"""Test key building with created_at and nested prefix."""
231+
key = _build_s3_key("test-uuid", created_at="2024-01-15T08:00:00Z", s3_path="data/archive")
232+
assert key == "data/archive/2024/01/15/test-uuid.vcon"
233+
219234

220235
class TestSave:
221236
"""Tests for the save function."""
@@ -225,6 +240,7 @@ def mock_vcon(self):
225240
"""Create a mock vCon object."""
226241
mock = MagicMock()
227242
mock.dumps.return_value = '{"uuid": "test-uuid", "vcon": "1.0.0"}'
243+
mock.created_at = "2025-12-10T15:30:00Z"
228244
return mock
229245

230246
@pytest.fixture
@@ -237,7 +253,7 @@ def base_opts(self):
237253
}
238254

239255
def test_save_basic(self, mock_vcon, base_opts):
240-
"""Test basic save operation."""
256+
"""Test basic save operation with date folder."""
241257
with patch("server.storage.s3.VconRedis") as mock_redis_class, \
242258
patch("server.storage.s3.boto3.client") as mock_boto_client:
243259

@@ -255,10 +271,10 @@ def test_save_basic(self, mock_vcon, base_opts):
255271

256272
call_args = mock_s3.put_object.call_args
257273
assert call_args.kwargs["Bucket"] == "test-bucket"
258-
assert call_args.kwargs["Key"] == "test-uuid.vcon"
274+
assert call_args.kwargs["Key"] == "2025/12/10/test-uuid.vcon"
259275

260276
def test_save_with_s3_path_prefix(self, mock_vcon, base_opts):
261-
"""Test save operation with s3_path prefix."""
277+
"""Test save operation with s3_path prefix and date folder."""
262278
base_opts["s3_path"] = "vcons"
263279

264280
with patch("server.storage.s3.VconRedis") as mock_redis_class, \
@@ -274,7 +290,7 @@ def test_save_with_s3_path_prefix(self, mock_vcon, base_opts):
274290
save("test-uuid", base_opts)
275291

276292
call_args = mock_s3.put_object.call_args
277-
assert call_args.kwargs["Key"] == "vcons/test-uuid.vcon"
293+
assert call_args.kwargs["Key"] == "vcons/2025/12/10/test-uuid.vcon"
278294

279295
def test_save_with_region(self, mock_vcon, base_opts):
280296
"""Test save operation with region specified."""

0 commit comments

Comments
 (0)