Skip to content

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

also testing without botocore

Victor Torres079af889e7d0
diff --git a/tests/test_feedexport.py b/tests/test_feedexport.py
index bfac06efc..520ca4a8f 100644
--- a/tests/test_feedexport.py
+++ b/tests/test_feedexport.py
@@ -237,7 +237,7 @@ class S3FeedStorageTest(unittest.TestCase):
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, 'custom-acl')
- def test_store_in_thread_without_acl(self):
+ def test_store_in_thread_botocore_without_acl(self):
storage = S3FeedStorage(
's3://mybucket/export.csv',
'access_key',
@@ -253,7 +253,7 @@ class S3FeedStorageTest(unittest.TestCase):
self.assertEqual(operation_name, 'PutObject')
self.assertNotIn('ACL', api_params)
- def test_store_in_thread_with_acl(self):
+ def test_store_in_thread_botocore_with_acl(self):
storage = S3FeedStorage(
's3://mybucket/export.csv',
'access_key',
@@ -270,6 +270,55 @@ class S3FeedStorageTest(unittest.TestCase):
self.assertEqual(operation_name, 'PutObject')
self.assertEqual(api_params.get('ACL'), 'custom-acl')
+ def test_store_in_thread_not_botocore_without_acl(self):
+ storage = S3FeedStorage(
+ 's3://mybucket/export.csv',
+ 'access_key',
+ 'secret_key',
+ )
+ self.assertEqual(storage.access_key, 'access_key')
+ self.assertEqual(storage.secret_key, 'secret_key')
+ self.assertEqual(storage.acl, None)
+
+ storage.is_botocore = False
+ storage.connect_s3 = mock.MagicMock()
+ self.assertFalse(storage.is_botocore)
+
+ storage._store_in_thread(BytesIO(b'test file'))
+
+ conn = storage.connect_s3(*storage.connect_s3.call_args)
+ bucket = conn.get_bucket(*conn.get_bucket.call_args)
+ key = bucket.new_key(*bucket.new_key.call_args)
+ self.assertNotIn(
+ dict(policy='custom-acl'),
+ key.set_contents_from_file.call_args
+ )
+
+ def test_store_in_thread_not_botocore_with_acl(self):
+ storage = S3FeedStorage(
+ 's3://mybucket/export.csv',
+ 'access_key',
+ 'secret_key',
+ 'custom-acl'
+ )
+ self.assertEqual(storage.access_key, 'access_key')
+ self.assertEqual(storage.secret_key, 'secret_key')
+ self.assertEqual(storage.acl, 'custom-acl')
+
+ storage.is_botocore = False
+ storage.connect_s3 = mock.MagicMock()
+ self.assertFalse(storage.is_botocore)
+
+ storage._store_in_thread(BytesIO(b'test file'))
+
+ conn = storage.connect_s3(*storage.connect_s3.call_args)
+ bucket = conn.get_bucket(*conn.get_bucket.call_args)
+ key = bucket.new_key(*bucket.new_key.call_args)
+ self.assertIn(
+ dict(policy='custom-acl'),
+ key.set_contents_from_file.call_args
+ )
+
class StdoutFeedStorageTest(unittest.TestCase):