Skip to content

Commit cb9c92c

Browse files
authored
Fix webp prefix, fixes #171 (#200)
1 parent 330f9f3 commit cb9c92c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ dmypy.json
130130
test-results/
131131
cobertura.xml
132132
coverage
133+
coverage.lcov
133134
cc-test-reporter
134135

135136
.vscode

tests/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def get_config(self) -> Config:
4343
cfg.STORAGE = "thumbor_aws.storage"
4444
cfg.RESULT_STORAGE = "thumbor_aws.result_storage"
4545

46+
cfg.AUTO_WEBP = True
47+
4648
cfg.AWS_DEFAULT_LOCATION = (
4749
"https://{bucket_name}.s3.localhost.localstack.cloud:4566"
4850
)
@@ -78,6 +80,8 @@ def get_compatibility_config(self) -> Config:
7880
cfg.STORAGE = "thumbor_aws.storage"
7981
cfg.RESULT_STORAGE = "thumbor_aws.result_storage"
8082

83+
cfg.AUTO_WEBP = True
84+
8185
cfg.AWS_DEFAULT_LOCATION = (
8286
"https://{bucket_name}.s3.localhost.localstack.cloud:4566"
8387
)

tests/test_result_storage.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def region_name(self):
3838
return self.context.config.AWS_RESULT_STORAGE_REGION_NAME
3939

4040
@gen_test
41-
async def test_can_put_file_in_s3(self):
41+
async def test_can_put_file_in_s3_with_webp(self):
4242
"""
4343
Verifies that submitting an image to S3 through
4444
Result Storage works and the image is there
@@ -51,6 +51,33 @@ async def test_can_put_file_in_s3(self):
5151

5252
path = await storage.put(expected)
5353

54+
expect(path).to_equal(
55+
f"https://{self.bucket_name}.s3.localhost.localstack.cloud:4566"
56+
f"{self._prefix}/auto_webp/{filepath}",
57+
)
58+
status, data, _ = await storage.get_data(
59+
self.bucket_name, f"{self._prefix}/auto_webp/{filepath}"
60+
)
61+
expect(status).to_equal(200)
62+
expect(data).to_equal(expected)
63+
64+
@gen_test
65+
async def test_can_put_file_in_s3_without_webp(self):
66+
"""
67+
Verifies that submitting an image to S3 through
68+
Result Storage works and the image is there
69+
"""
70+
await self.ensure_bucket()
71+
filepath = f"test/can_put_file_{uuid4()}"
72+
73+
context_without_webp = self.get_context()
74+
context_without_webp.request = Mock(url=filepath)
75+
context_without_webp.request.accepts_webp = False
76+
storage = ResultStorage(context_without_webp)
77+
expected = self.test_images["default"]
78+
79+
path = await storage.put(expected)
80+
5481
expect(path).to_equal(
5582
f"https://{self.bucket_name}.s3.localhost.localstack.cloud:4566"
5683
f"{self._prefix}/{filepath}",

thumbor_aws/result_storage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def is_auto_webp(self) -> bool:
161161

162162
@property
163163
def prefix(self) -> str:
164-
return ("auto_webp/" if self.is_auto_webp else "") + self.root_path
164+
return self.root_path + ("/auto_webp" if self.is_auto_webp else "")
165165

166166
async def get(self) -> ResultStorageResult:
167167
path = self.context.request.url

0 commit comments

Comments
 (0)