Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Add tests.

djunzue9d48f8a8ed7
diff --git a/tests/test_pipeline_files.py b/tests/test_pipeline_files.py
index 77e75d5ac..f480b0c18 100644
--- a/tests/test_pipeline_files.py
+++ b/tests/test_pipeline_files.py
@@ -183,6 +183,35 @@ class FilesPipelineTestCaseFields(unittest.TestCase):
self.assertEqual(item['stored_file'], [results[0][1]])
+class FilesPipelineTestCaseCustomSettings(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = mkdtemp()
+ self.pipeline = FilesPipeline(self.tempdir)
+ self.default_settings = Settings()
+
+ def tearDown(self):
+ rmtree(self.tempdir)
+
+ def test_expires(self):
+ another_pipeline = FilesPipeline.from_settings(Settings({'FILES_STORE': self.tempdir,
+ 'FILES_EXPIRES': 42}))
+ self.assertEqual(self.pipeline.expires, self.default_settings.getint('FILES_EXPIRES'))
+ self.assertEqual(another_pipeline.expires, 42)
+
+ def test_files_urls_field(self):
+ another_pipeline = FilesPipeline.from_settings(Settings({'FILES_STORE': self.tempdir,
+ 'FILES_URLS_FIELD': 'funny_field'}))
+ self.assertEqual(self.pipeline.files_urls_field, self.default_settings.get('FILES_URLS_FIELD'))
+ self.assertEqual(another_pipeline.files_urls_field, 'funny_field')
+
+ def test_files_result_field(self):
+ another_pipeline = FilesPipeline.from_settings(Settings({'FILES_STORE': self.tempdir,
+ 'FILES_RESULT_FIELD': 'funny_field'}))
+ self.assertEqual(self.pipeline.files_result_field, self.default_settings.get('FILES_RESULT_FIELD'))
+ self.assertEqual(another_pipeline.files_result_field, 'funny_field')
+
+
class TestS3FilesStore(unittest.TestCase):
@defer.inlineCallbacks
def test_persist(self):
diff --git a/tests/test_pipeline_images.py b/tests/test_pipeline_images.py
index f52fb4d3d..f48547b0f 100644
--- a/tests/test_pipeline_images.py
+++ b/tests/test_pipeline_images.py
@@ -205,6 +205,54 @@ class ImagesPipelineTestCaseFields(unittest.TestCase):
self.assertEqual(item['stored_image'], [results[0][1]])
+class ImagesPipelineTestCaseCustomSettings(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = mkdtemp()
+ self.pipeline = ImagesPipeline(self.tempdir)
+ self.default_settings = Settings()
+
+ def tearDown(self):
+ rmtree(self.tempdir)
+
+ def test_expires(self):
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_EXPIRES': 42}))
+ self.assertEqual(self.pipeline.expires, self.default_settings.getint('IMAGES_EXPIRES'))
+ self.assertEqual(another_pipeline.expires, 42)
+
+ def test_images_urls_field(self):
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_URLS_FIELD': 'funny_field'}))
+ self.assertEqual(self.pipeline.images_urls_field, self.default_settings.get('IMAGES_URLS_FIELD'))
+ self.assertEqual(another_pipeline.images_urls_field, 'funny_field')
+
+ def test_images_result_field(self):
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_RESULT_FIELD': 'funny_field'}))
+ self.assertEqual(self.pipeline.images_result_field, self.default_settings.get('IMAGES_RESULT_FIELD'))
+ self.assertEqual(another_pipeline.images_result_field, 'funny_field')
+
+ def test_min_width(self):
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_MIN_WIDTH': 42}))
+ self.assertEqual(self.pipeline.min_width, self.default_settings.getint('IMAGES_MIN_WIDTH'))
+ self.assertEqual(another_pipeline.min_width, 42)
+
+ def test_min_height(self):
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_MIN_HEIGHT': 42}))
+ self.assertEqual(self.pipeline.min_height, self.default_settings.getint('IMAGES_MIN_HEIGHT'))
+ self.assertEqual(another_pipeline.min_height, 42)
+
+ def test_thumbs(self):
+ custom_thumbs = {'small': (50, 50), 'big': (270, 270)}
+ another_pipeline = ImagesPipeline.from_settings(Settings({'IMAGES_STORE': self.tempdir,
+ 'IMAGES_THUMBS': custom_thumbs}))
+ self.assertEqual(self.pipeline.thumbs, self.default_settings.get('IMAGES_THUMBS'))
+ self.assertEqual(another_pipeline.thumbs, custom_thumbs)
+
+
def _create_image(format, *a, **kw):
buf = TemporaryFile()
Image.new(*a, **kw).save(buf, format)