-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize images loaded from storage
- Loading branch information
1 parent
bb57115
commit 7915742
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest.mock import patch | ||
|
||
from preggy import expect | ||
from tornado.testing import gen_test | ||
|
||
from tests.base import TestCase | ||
from tests.fixtures.images import default_image | ||
from thumbor.engines.pil import Engine | ||
from thumbor.loaders import LoaderResult | ||
|
||
|
||
class BaseHandlerLoadingNormalizeImagesTestCase(TestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.storage_patcher = patch( | ||
"thumbor.storages.file_storage.Storage" | ||
) | ||
self.storage_mock = self.storage_patcher.start() | ||
self.loader_patcher = patch("thumbor.loaders.http_loader") | ||
self.loader_mock = self.loader_patcher.start() | ||
|
||
def tearDown(self): | ||
self.storage_patcher.stop() | ||
self.loader_patcher.stop() | ||
|
||
@gen_test | ||
async def test_can_normalize_image_loaded_from_storage(self): | ||
self.storage_mock.get.return_value = default_image() | ||
self.context.config.MAX_HEIGHT = 1 | ||
response = await self.async_fetch("/unsafe/smart/image.jpg") | ||
expect(response.code).to_equal(200) | ||
|
||
engine = Engine(self.context) | ||
engine.load(response.body, None) | ||
expect(engine.size).to_equal((1, 1)) | ||
|
||
@gen_test | ||
async def test_can_normalize_image_loaded_from_upstream(self): | ||
self.storage_mock.get.return_value = None | ||
self.loader_mock.load.return_value = LoaderResult(buffer=default_image()) | ||
self.context.config.MAX_HEIGHT = 1 | ||
response = await self.async_fetch("/unsafe/smart/image.jpg") | ||
expect(response.code).to_equal(200) | ||
|
||
engine = Engine(self.context) | ||
engine.load(response.body, None) | ||
expect(engine.size).to_equal((1, 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters