|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
import io
|
|
import io
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
|
|
+from unittest import mock
|
|
|
|
|
|
import boto3
|
|
import boto3
|
|
import pytest
|
|
import pytest
|
|
@@ -152,6 +153,30 @@ async def test_remove_multiple_empty_list(s3_gateway: S3Gateway, s3_bucket):
|
|
await s3_gateway.remove_multiple([])
|
|
await s3_gateway.remove_multiple([])
|
|
|
|
|
|
|
|
|
|
|
|
+async def test_remove_filtered_all(s3_gateway: S3Gateway, multiple_objects):
|
|
|
|
+ await s3_gateway.remove_filtered([])
|
|
|
|
+
|
|
|
|
+ for key in multiple_objects:
|
|
|
|
+ assert await s3_gateway.get(key) is None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+async def test_remove_filtered_prefix(s3_gateway: S3Gateway, multiple_objects):
|
|
|
|
+ await s3_gateway.remove_filtered([Filter(field="prefix", values=["raster-2/"])])
|
|
|
|
+
|
|
|
|
+ assert await s3_gateway.get(multiple_objects[0]) is not None
|
|
|
|
+ for key in multiple_objects[1:]:
|
|
|
|
+ assert await s3_gateway.get(key) is None
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@mock.patch("clean_python.s3.s3_gateway.AWS_LIMIT", new=1)
|
|
|
|
+async def test_remove_filtered_pagination(s3_gateway: S3Gateway, multiple_objects):
|
|
|
|
+ await s3_gateway.remove_filtered([Filter(field="prefix", values=["raster-2/"])])
|
|
|
|
+
|
|
|
|
+ assert await s3_gateway.get(multiple_objects[0]) is not None
|
|
|
|
+ for key in multiple_objects[1:]:
|
|
|
|
+ assert await s3_gateway.get(key) is None
|
|
|
|
+
|
|
|
|
+
|
|
async def test_filter(s3_gateway: S3Gateway, multiple_objects):
|
|
async def test_filter(s3_gateway: S3Gateway, multiple_objects):
|
|
actual = await s3_gateway.filter([], params=PageOptions(limit=10))
|
|
actual = await s3_gateway.filter([], params=PageOptions(limit=10))
|
|
assert len(actual) == 4
|
|
assert len(actual) == 4
|
|
@@ -166,13 +191,6 @@ async def test_filter_empty(s3_gateway: S3Gateway, s3_bucket):
|
|
assert actual == []
|
|
assert actual == []
|
|
|
|
|
|
|
|
|
|
-async def test_filter_with_prefix(s3_gateway: S3Gateway, multiple_objects):
|
|
|
|
- actual = await s3_gateway.filter(
|
|
|
|
- [Filter(field="prefix", values=["raster-2/"])], params=PageOptions(limit=10)
|
|
|
|
- )
|
|
|
|
- assert len(actual) == 3
|
|
|
|
-
|
|
|
|
-
|
|
|
|
async def test_filter_with_limit(s3_gateway: S3Gateway, multiple_objects):
|
|
async def test_filter_with_limit(s3_gateway: S3Gateway, multiple_objects):
|
|
actual = await s3_gateway.filter([], params=PageOptions(limit=2))
|
|
actual = await s3_gateway.filter([], params=PageOptions(limit=2))
|
|
assert len(actual) == 2
|
|
assert len(actual) == 2
|
|
@@ -189,6 +207,14 @@ async def test_filter_with_cursor(s3_gateway: S3Gateway, multiple_objects):
|
|
assert actual[1]["id"] == "raster-2/foo"
|
|
assert actual[1]["id"] == "raster-2/foo"
|
|
|
|
|
|
|
|
|
|
|
|
+async def test_filter_by_prefix(s3_gateway: S3Gateway, multiple_objects):
|
|
|
|
+ actual = await s3_gateway.filter([Filter(field="prefix", values=["raster-1/"])])
|
|
|
|
+ assert len(actual) == 1
|
|
|
|
+
|
|
|
|
+ actual = await s3_gateway.filter([Filter(field="prefix", values=["raster-2/"])])
|
|
|
|
+ assert len(actual) == 3
|
|
|
|
+
|
|
|
|
+
|
|
async def test_get(s3_gateway: S3Gateway, object_in_s3):
|
|
async def test_get(s3_gateway: S3Gateway, object_in_s3):
|
|
actual = await s3_gateway.get(object_in_s3)
|
|
actual = await s3_gateway.get(object_in_s3)
|
|
assert actual["id"] == "object-in-s3"
|
|
assert actual["id"] == "object-in-s3"
|