本文整理汇总了Python中moto.mock_s3方法的典型用法代码示例。如果您正苦于以下问题:Python moto.mock_s3方法的具体用法?Python moto.mock_s3怎么用?Python moto.mock_s3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moto
的用法示例。
在下文中一共展示了moto.mock_s3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cr
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def cr(self):
with moto.mock_s3():
cr = config_rules.ConfigRules(logging)
yield cr
# def test_s3_bucket_sse_enabled(self, cr):
# # create bucket
# cr.client_s3.create_bucket(Bucket="test")
# # test s3_bucket_server_side_encryption_enabled function
# cr.s3_bucket_server_side_encryption_enabled("test")
# # validate test
# response = cr.client_s3.get_bucket_encryption(Bucket="test")
# print(response)
# assert (
# response["ServerSideEncryptionConfiguration"]["Rules"][0][
# "ApplyServerSideEncryptionByDefault"
# ]["SSEAlgorithm"]
# == "AES256"
# )
示例2: setUp
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setUp(self):
self.bucket_name = 'palp-cfn-json'
basedir = os.path.dirname(__file__)
self.project = Project(basedir=basedir,
name='palp', version='123')
self.test_files = [
(os.path.join(basedir, 'templates'), 'alarm-topic.yml'),
(os.path.join(basedir, 'templates'), 'ecs-simple-webapp.yml')]
self.project.set_property('bucket_name', self.bucket_name)
self.project.set_property('template_key_prefix', 'palp/')
self.project.set_property('template_files', self.test_files)
self.project.set_property(
'template_file_access_control', 'bucket-owner-full-control')
self.my_mock_s3 = mock_s3()
self.my_mock_s3.start()
self.s3 = boto3.resource('s3')
self.s3.create_bucket(Bucket=self.bucket_name)
示例3: setUp
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setUp(self):
self.tempdir = tempfile.mkdtemp(prefix='palp-')
self.project = Project(
basedir=self.tempdir, name='palp', version='123')
self.project.set_property('dir_target', 'target')
self.bucket_name = 'palp-lambda-zips'
self.project.set_property(
'lambda_file_access_control', 'bucket-owner-full-control')
self.project.set_property('bucket_name', self.bucket_name)
self.project.set_property('bucket_prefix', '')
self.dir_target = os.path.join(self.tempdir, 'target')
os.mkdir(self.dir_target)
self.zipfile_name = os.path.join(self.dir_target, 'palp.zip')
self.test_data = b'testdata'
with open(self.zipfile_name, 'wb') as fp:
fp.write(self.test_data)
self.my_mock_s3 = mock_s3()
self.my_mock_s3.start()
self.s3 = boto3.resource('s3')
self.s3.create_bucket(Bucket=self.bucket_name)
示例4: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setup(self):
"""LookupTables - Setup S3 bucket mocking"""
self.config = load_config('tests/unit/conf')
self.s3_mock = mock_s3()
self.s3_mock.start()
self.dynamodb_mock = mock_dynamodb2()
self.dynamodb_mock.start()
self._put_mock_data()
self._lookup_tables = LookupTables.get_instance(
config=self.config,
reset=True
)
示例5: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setup(self):
"""LookupTables - Setup S3 bucket mocking"""
self.buckets_info = {'bucket_name': ['foo.json', 'bar.json']}
self.config = load_config('tests/unit/conf')
self.s3_mock = mock_s3()
self.s3_mock.start()
self._foo_driver = construct_persistence_driver(
self.config['lookup_tables']['tables']['foo']
)
self._bar_driver = construct_persistence_driver(
self.config['lookup_tables']['tables']['bar']
)
self._bad_driver = construct_persistence_driver(
{
'driver': 's3',
'bucket': 'bucket_name',
'key': 'invalid-key',
}
)
self._put_mock_tables()
示例6: test_s3_levels
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def test_s3_levels(self):
with moto.mock_s3():
self._write_test_cube_pyramid()
s3 = s3fs.S3FileSystem(key='test_fake_id',
secret='test_fake_secret',
client_kwargs=dict(endpoint_url="https://s3.amazonaws.com"))
ml_dataset = ObjectStorageMultiLevelDataset(s3,
"xcube-test/cube-1-250-250.levels",
chunk_cache_capacity=1000 * 1000 * 1000)
self.assertIsNotNone(ml_dataset)
self.assertEqual(3, ml_dataset.num_levels)
self.assertEqual((250, 250), ml_dataset.tile_grid.tile_size)
self.assertEqual(2, ml_dataset.tile_grid.num_level_zero_tiles_x)
self.assertEqual(1, ml_dataset.tile_grid.num_level_zero_tiles_y)
self.assertEqual(761904762, ml_dataset.get_chunk_cache_capacity(0))
self.assertEqual(190476190, ml_dataset.get_chunk_cache_capacity(1))
self.assertEqual(47619048, ml_dataset.get_chunk_cache_capacity(2))
示例7: test_bypass
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def test_bypass(self):
# given:
opts = create_s3_azure_file_bypass_simple_opts()
# when:
with moto.mock_s3(), mock.patch('azure.storage.file.FileService') as azure:
s3_conn = boto.connect_s3()
bucket = s3_conn.create_bucket(opts['reader']['options']['bucket'])
keys = ['some_prefix/{}'.format(k) for k in ['some', 'keys', 'here']]
create_s3_keys(bucket, keys)
exporter = BasicExporter(opts)
exporter.export()
# then:
self.assertEquals(exporter.writer.get_metadata('items_count'), 0,
"No items should be read")
self.assertEquals(exporter.reader.get_metadata('read_items'), 0,
"No items should get written")
azure_puts = [
call for call in azure.mock_calls if call[0] == '().copy_file'
]
self.assertEquals(len(azure_puts), len(keys),
"all keys should be put into Azure files")
示例8: setUp
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setUp(self):
self.mock_s3 = moto.mock_s3()
self.mock_s3.start()
self.s3_conn = boto.connect_s3()
self.s3_conn.create_bucket('last_bucket')
bucket = self.s3_conn.get_bucket('last_bucket')
key = bucket.new_key('test_list/LAST')
self.pointers = ['pointer1', 'pointer2', 'pointer3', '']
key.set_contents_from_string('\r\n'.join(self.pointers))
key.close()
for key_name in POINTER_KEYS:
key = bucket.new_key(key_name)
out = StringIO.StringIO()
with gzip.GzipFile(fileobj=out, mode='w') as f:
f.write(json.dumps({'name': key_name}))
key.set_contents_from_string(out.getvalue())
key.close()
self.options_prefix_pointer = {
'bucket': 'last_bucket',
'aws_access_key_id': 'KEY',
'aws_secret_access_key': 'SECRET',
'prefix_pointer': 'test_list/LAST'
}
示例9: setUp
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def setUp(self):
self.mock_s3 = moto.mock_s3()
self.mock_s3.start()
self.s3_conn = boto.connect_s3()
self.s3_conn.create_bucket('source_bucket')
self.source_bucket = self.s3_conn.get_bucket('source_bucket')
self.data = [
{'name': 'Roberto', 'birthday': '12/05/1987'},
{'name': 'Claudia', 'birthday': '21/12/1985'},
]
with closing(self.source_bucket.new_key('some_prefix/test_key')) as key:
with TmpFile() as tmp_filename:
with open(tmp_filename, 'w') as f:
f.write(json.dumps(self.data))
with open(tmp_filename) as f:
self.key_md5 = compute_md5(f)
key.metadata = {'total': 2, 'md5': self.key_md5}
key.set_contents_from_string(json.dumps(self.data))
self.tmp_bypass_resume_file = 'tests/data/tmp_s3_bypass_resume_persistence.pickle'
shutil.copyfile('tests/data/s3_bypass_resume_persistence.pickle',
self.tmp_bypass_resume_file)
示例10: test_with_s3_url
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def test_with_s3_url(compression):
boto3 = pytest.importorskip('boto3')
pytest.importorskip('s3fs')
if compression == 'xz':
tm._skip_if_no_lzma()
df = pd.read_json('{"a": [1, 2, 3], "b": [4, 5, 6]}')
with moto.mock_s3():
conn = boto3.resource("s3", region_name="us-east-1")
bucket = conn.create_bucket(Bucket="pandas-test")
with tm.ensure_clean() as path:
df.to_json(path, compression=compression)
with open(path, 'rb') as f:
bucket.put_object(Key='test-1', Body=f)
roundtripped_df = pd.read_json('s3://pandas-test/test-1',
compression=compression)
assert_frame_equal(df, roundtripped_df)
示例11: test_read_from_s3_url
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def test_read_from_s3_url(self):
boto3 = pytest.importorskip('boto3')
pytest.importorskip('s3fs')
with moto.mock_s3():
conn = boto3.resource("s3", region_name="us-east-1")
conn.create_bucket(Bucket="pandas-test")
file_name = os.path.join(self.dirpath, 'test1' + self.ext)
with open(file_name, 'rb') as f:
conn.Bucket("pandas-test").put_object(Key="test1" + self.ext,
Body=f)
url = ('s3://pandas-test/test1' + self.ext)
url_table = read_excel(url)
local_table = self.get_exceldf('test1')
tm.assert_frame_equal(url_table, local_table)
示例12: sh
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def sh(self):
with moto.mock_s3():
sh = security_hub_rules.SecurityHubRules(logging)
yield sh
示例13: s3_client
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def s3_client():
mock = moto.mock_s3()
mock.start()
boto_client = boto3.client(
"s3", aws_access_key_id="", aws_secret_access_key="", aws_session_token=""
)
bucket_name = fake.user_name()
boto_client.create_bucket(Bucket=bucket_name)
yield S3SyncClient(boto_client, bucket_name, fake.uri_path())
mock.stop()
示例14: my_mock_s3
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def my_mock_s3(request):
"""The purpose of this fixture is to setUp/tearDown the moto library"""
m = mock_s3()
m.start()
def fin():
m.stop()
request.addfinalizer(fin)
示例15: start_mock
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_s3 [as 别名]
def start_mock(self):
self.mock_s3 = mock_s3()
self.mock_ddb = mock_dynamodb2()
self.mock_s3.start()
self.mock_ddb.start()
self.bucket = csv_s3
self.s3 = boto3.client('s3')
self.s3.create_bucket(Bucket=self.bucket)