Skip to content

Commit

Permalink
Fix webp prefix, fixes #171 (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef authored Mar 14, 2024
1 parent 330f9f3 commit cb9c92c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ dmypy.json
test-results/
cobertura.xml
coverage
coverage.lcov
cc-test-reporter

.vscode
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def get_config(self) -> Config:
cfg.STORAGE = "thumbor_aws.storage"
cfg.RESULT_STORAGE = "thumbor_aws.result_storage"

cfg.AUTO_WEBP = True

cfg.AWS_DEFAULT_LOCATION = (
"https://{bucket_name}.s3.localhost.localstack.cloud:4566"
)
Expand Down Expand Up @@ -78,6 +80,8 @@ def get_compatibility_config(self) -> Config:
cfg.STORAGE = "thumbor_aws.storage"
cfg.RESULT_STORAGE = "thumbor_aws.result_storage"

cfg.AUTO_WEBP = True

cfg.AWS_DEFAULT_LOCATION = (
"https://{bucket_name}.s3.localhost.localstack.cloud:4566"
)
Expand Down
29 changes: 28 additions & 1 deletion tests/test_result_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def region_name(self):
return self.context.config.AWS_RESULT_STORAGE_REGION_NAME

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

path = await storage.put(expected)

expect(path).to_equal(
f"https://{self.bucket_name}.s3.localhost.localstack.cloud:4566"
f"{self._prefix}/auto_webp/{filepath}",
)
status, data, _ = await storage.get_data(
self.bucket_name, f"{self._prefix}/auto_webp/{filepath}"
)
expect(status).to_equal(200)
expect(data).to_equal(expected)

@gen_test
async def test_can_put_file_in_s3_without_webp(self):
"""
Verifies that submitting an image to S3 through
Result Storage works and the image is there
"""
await self.ensure_bucket()
filepath = f"test/can_put_file_{uuid4()}"

context_without_webp = self.get_context()
context_without_webp.request = Mock(url=filepath)
context_without_webp.request.accepts_webp = False
storage = ResultStorage(context_without_webp)
expected = self.test_images["default"]

path = await storage.put(expected)

expect(path).to_equal(
f"https://{self.bucket_name}.s3.localhost.localstack.cloud:4566"
f"{self._prefix}/{filepath}",
Expand Down
2 changes: 1 addition & 1 deletion thumbor_aws/result_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def is_auto_webp(self) -> bool:

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

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

0 comments on commit cb9c92c

Please sign in to comment.