code
stringlengths
3
6.57k
open(path, 'rb')
self.assertEqual(fp.read()
storage.store(BytesIO(b"new content")
open(path, 'rb')
self.assertEqual(fp.read()
os.unlink(path)
BlockingFeedStorageTest(unittest.TestCase)
get_test_spider(self, settings=None)
TestSpider(scrapy.Spider)
get_crawler(settings_dict=settings)
TestSpider.from_crawler(crawler)
test_default_temp_dir(self)
BlockingFeedStorage()
b.open(self.get_test_spider()
os.path.dirname(tmp.name)
self.assertEqual(tmp_path, tempfile.gettempdir()
test_temp_file(self)
BlockingFeedStorage()
os.path.dirname(os.path.abspath(__file__)
self.get_test_spider({'FEED_TEMPDIR': tests_path})
b.open(spider)
os.path.dirname(tmp.name)
self.assertEqual(tmp_path, tests_path)
test_invalid_folder(self)
BlockingFeedStorage()
os.path.dirname(os.path.abspath(__file__)
os.path.join(tests_path, 'invalid_path')
self.get_test_spider({'FEED_TEMPDIR': invalid_path})
self.assertRaises(OSError, b.open, spider=spider)
S3FeedStorageTest(unittest.TestCase)
test_parse_credentials(self)
unittest.SkipTest("S3FeedStorage requires boto")
get_crawler(settings_dict=aws_credentials)
self.assertEqual(storage.access_key, 'settings_key')
self.assertEqual(storage.secret_key, 'settings_secret')
self.assertEqual(storage.access_key, 'settings_key')
self.assertEqual(storage.secret_key, 'settings_secret')
self.assertEqual(storage.access_key, 'uri_key')
self.assertEqual(storage.secret_key, 'uri_secret')
warnings.catch_warnings(record=True)
S3FeedStorage('s3://mybucket/export.csv')
self.assertEqual(storage.access_key, 'conf_key')
self.assertEqual(storage.secret_key, 'conf_secret')
self.assertTrue('without AWS keys' in str(w[-1].message)
test_store(self)
assert_aws_environ()
os.environ.get('S3_TEST_FILE_URI')
unittest.SkipTest("No S3 URI available for testing")
os.environ.get('AWS_ACCESS_KEY_ID')
os.environ.get('AWS_SECRET_ACCESS_KEY')
S3FeedStorage(uri, access_key, secret_key)
verifyObject(IFeedStorage, storage)
storage.open(scrapy.Spider("default")
file.write(expected_content)
storage.store(file)
urlparse(uri)
get_s3_content_and_delete(u.hostname, u.path[1:])
self.assertEqual(content, expected_content)
test_init_without_acl(self)
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, None)
test_init_with_acl(self)
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, 'custom-acl')
test_from_crawler_without_acl(self)
get_crawler(settings_dict=settings)
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, None)
test_from_crawler_with_acl(self)
get_crawler(settings_dict=settings)
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, 'custom-acl')
test_store_botocore_without_acl(self)
unittest.SkipTest('botocore is required')
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, None)
mock.MagicMock()
storage.store(BytesIO(b'test file')
self.assertNotIn('ACL', storage.s3_client.put_object.call_args[1])
test_store_botocore_with_acl(self)
unittest.SkipTest('botocore is required')
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, 'custom-acl')
mock.MagicMock()
storage.store(BytesIO(b'test file')
get('ACL')
test_store_not_botocore_without_acl(self)
self.assertEqual(storage.access_key, 'access_key')
self.assertEqual(storage.secret_key, 'secret_key')
self.assertEqual(storage.acl, None)
mock.MagicMock()
self.assertFalse(storage.is_botocore)
storage.store(BytesIO(b'test file')
storage.connect_s3(*storage.connect_s3.call_args)