mirror of https://github.com/scrapy/scrapy.git
Test the life cycle of a storage file
This commit is contained in:
parent
5735e93541
commit
d599fff2b9
|
|
@ -1517,6 +1517,61 @@ class FeedExportTest(FeedExportTestBase):
|
|||
data = yield self.exported_data(items, settings)
|
||||
self.assertEqual(row['expected'], data[feed_options['format']])
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_storage_file_no_postprocessing(self):
|
||||
|
||||
@implementer(IFeedStorage)
|
||||
class Storage:
|
||||
|
||||
def __init__(self, uri, *, feed_options=None):
|
||||
pass
|
||||
|
||||
def open(self, spider):
|
||||
Storage.open_file = tempfile.NamedTemporaryFile(prefix='feed-')
|
||||
return Storage.open_file
|
||||
|
||||
def store(self, file):
|
||||
Storage.store_file = file
|
||||
file.close()
|
||||
|
||||
settings = {
|
||||
'FEEDS': {self._random_temp_filename(): {'format': 'jsonlines'}},
|
||||
'FEED_STORAGES': {'file': Storage},
|
||||
}
|
||||
yield self.exported_no_data(settings)
|
||||
self.assertIs(Storage.open_file, Storage.store_file)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_storage_file_postprocessing(self):
|
||||
|
||||
@implementer(IFeedStorage)
|
||||
class Storage:
|
||||
|
||||
def __init__(self, uri, *, feed_options=None):
|
||||
pass
|
||||
|
||||
def open(self, spider):
|
||||
Storage.open_file = tempfile.NamedTemporaryFile(prefix='feed-')
|
||||
return Storage.open_file
|
||||
|
||||
def store(self, file):
|
||||
Storage.store_file = file
|
||||
file.close()
|
||||
|
||||
settings = {
|
||||
'FEEDS': {
|
||||
self._random_temp_filename(): {
|
||||
'format': 'jsonlines',
|
||||
'postprocessing': [
|
||||
'scrapy.extensions.postprocessing.GzipPlugin',
|
||||
],
|
||||
},
|
||||
},
|
||||
'FEED_STORAGES': {'file': Storage},
|
||||
}
|
||||
yield self.exported_no_data(settings)
|
||||
self.assertIs(Storage.open_file, Storage.store_file)
|
||||
|
||||
|
||||
class FeedPostProcessedExportsTest(FeedExportTestBase):
|
||||
__test__ = True
|
||||
|
|
|
|||
Loading…
Reference in New Issue