[image_pipeline] tests for class attrs backward compatibility

and docs about image pipeline settings.
This commit is contained in:
Pawel Miech 2016-05-18 12:04:52 +02:00
parent 4cef1a1d00
commit 6c67db3917
2 changed files with 27 additions and 0 deletions

View File

@ -191,6 +191,10 @@ For the Images Pipeline, set :setting:`IMAGES_URLS_FIELD` and/or
If you need something more complex and want to override the custom pipeline
behaviour, see :ref:`topics-media-pipeline-override`.
.. note:: If you have multiple image pipelines and you want to have different settings in different pipelines
you can either set class attributes in pipeline object or add custom settings keys and load them at pipeline
initialization.
Additional features
===================

View File

@ -256,6 +256,29 @@ class ImagesPipelineTestCaseCustomSettings(unittest.TestCase):
self.assertEqual(self.pipeline.thumbs, self.default_settings.get('IMAGES_THUMBS', default))
self.assertEqual(another_pipeline.thumbs, custom_thumbs)
def test_class_attrs_preserved(self):
class UserDefinedImagePipeline(ImagesPipeline):
MIN_WIDTH = 1000
# If image settings are not defined values are taken from class attributes.
pipeline = UserDefinedImagePipeline.from_settings(Settings({"IMAGES_STORE": self.tempdir}))
self.assertEqual(pipeline.min_width, 1000)
def test_class_attrs_not_preserved_if_settings_defined(self):
class UserDefinedImagePipeline(ImagesPipeline):
MIN_WIDTH = 1000
settings = {
"IMAGES_STORE": self.tempdir,
"IMAGES_MIN_WIDTH": 90
}
# If image settings are defined they override class attributes.
pipeline = UserDefinedImagePipeline.from_settings(Settings(settings))
self.assertEqual(pipeline.min_width, 90)
def _create_image(format, *a, **kw):
buf = TemporaryFile()