本文整理汇总了Python中moto.mock_dynamodb2方法的典型用法代码示例。如果您正苦于以下问题:Python moto.mock_dynamodb2方法的具体用法?Python moto.mock_dynamodb2怎么用?Python moto.mock_dynamodb2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moto
的用法示例。
在下文中一共展示了moto.mock_dynamodb2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [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
)
示例2: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def setup(self):
"""LookupTables - Setup S3 bucket mocking"""
self.config = load_config('tests/unit/conf')
self._dynamodb_mock = mock_dynamodb2()
self._dynamodb_mock.start()
self._driver = construct_persistence_driver(
self.config['lookup_tables']['tables']['dinosaur']
)
self._bad_driver = construct_persistence_driver(
{
'driver': 'dynamodb',
'table': 'table???',
'partition_key': '??',
'value_key': '?zlaerf',
}
)
self._put_mock_tables()
示例3: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def setup(self):
"""Alert Table - Create mock table and alerts"""
# pylint: disable=attribute-defined-outside-init
self.dynamo_mock = mock_dynamodb2()
self.dynamo_mock.start()
setup_mock_alerts_table(_ALERTS_TABLE)
self.alert_table = alert_table.AlertTable(_ALERTS_TABLE)
self.alerts = [
alert_module.Alert(
'even' if i % 2 == 0 else 'odd',
{'key1': 'value1', 'key2': 'value2'},
{'aws-firehose:alerts', 'aws-s3:test-bucket', 'slack:test-channel'},
)
for i in range(3)
]
self.alert_table.add_alerts(self.alerts)
示例4: example_table
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def example_table():
mock_dynamodb2().start(reset=False)
ddb = boto3.client("dynamodb", region_name=TEST_REGION_NAME)
ddb.create_table(
TableName=TEST_TABLE_NAME,
KeySchema=[
{"AttributeName": "partition_attribute", "KeyType": "HASH"},
{"AttributeName": "sort_attribute", "KeyType": "RANGE"},
],
AttributeDefinitions=[
{"AttributeName": name, "AttributeType": value["type"]} for name, value in TEST_INDEX.items()
],
ProvisionedThroughput={"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
)
yield
ddb.delete_table(TableName=TEST_TABLE_NAME)
mock_dynamodb2().stop()
示例5: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def setup(self):
with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts():
setup = lambda_handler.Setup(logging)
yield setup
示例6: start_mock
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [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)
示例7: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def setup(self):
"""Rule Table - Create mock table and rules"""
# pylint: disable=attribute-defined-outside-init
self.dynamo_mock = mock_dynamodb2()
self.dynamo_mock.start()
setup_mock_rules_table(_RULES_TABLE)
self.rule_table = rule_table.RuleTable(_RULES_TABLE)
示例8: setup
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def setup(self):
"""RulePromoter - Setup"""
# pylint: disable=attribute-defined-outside-init
self.dynamo_mock = mock_dynamodb2()
self.dynamo_mock.start()
with patch('streamalert.rule_promotion.promoter.load_config') as config_mock, \
patch('streamalert.rule_promotion.promoter.StatsPublisher', Mock()), \
patch('boto3.client', _mock_boto), \
patch.dict(os.environ, {'AWS_DEFAULT_REGION': 'us-east-1'}):
setup_mock_rules_table(_RULES_TABLE)
config_mock.return_value = config.load_config('tests/unit/conf/')
self.promoter = RulePromoter()
self._add_fake_stats()
示例9: dynamodb
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def dynamodb(aws_credentials):
with mock_dynamodb2():
yield boto3.resource('dynamodb', region_name='us-east-1')
示例10: test_class
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def test_class(self):
with moto.mock_dynamodb2():
whitelist = {}
settings = {
"general": {"dry_run": False},
"services": {"dynamodb": {"tables": {"clean": True, "ttl": -1}}},
}
resource_tree = {"AWS": {}}
test_class = dynamodb_cleanup.DynamoDBCleanup(
logging, whitelist, settings, resource_tree, "ap-southeast-2"
)
yield test_class
示例11: mock_db
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def mock_db(request):
"""We never want to use the real dynamodb."""
mock = mock_dynamodb2()
mock.start()
request.addfinalizer(mock.stop)
示例12: table_with_local_secondary_indexes
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def table_with_local_secondary_indexes():
mock_dynamodb2().start(reset=False)
ddb = boto3.client("dynamodb", region_name=TEST_REGION_NAME)
ddb.create_table(
TableName=TEST_TABLE_NAME,
KeySchema=[
{"AttributeName": "partition_attribute", "KeyType": "HASH"},
{"AttributeName": "sort_attribute", "KeyType": "RANGE"},
],
LocalSecondaryIndexes=[
{
"IndexName": "lsi-1",
"KeySchema": [{"AttributeName": "secondary_index_1", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
},
{
"IndexName": "lsi-2",
"KeySchema": [{"AttributeName": "secondary_index_2", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
},
],
AttributeDefinitions=[
{"AttributeName": name, "AttributeType": value["type"]}
for name, value in list(TEST_INDEX.items()) + list(SECONDARY_INDEX.items())
],
ProvisionedThroughput={"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
)
yield
ddb.delete_table(TableName=TEST_TABLE_NAME)
mock_dynamodb2().stop()
示例13: table_with_global_secondary_indexes
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def table_with_global_secondary_indexes():
mock_dynamodb2().start(reset=False)
ddb = boto3.client("dynamodb", region_name=TEST_REGION_NAME)
ddb.create_table(
TableName=TEST_TABLE_NAME,
KeySchema=[
{"AttributeName": "partition_attribute", "KeyType": "HASH"},
{"AttributeName": "sort_attribute", "KeyType": "RANGE"},
],
GlobalSecondaryIndexes=[
{
"IndexName": "gsi-1",
"KeySchema": [{"AttributeName": "secondary_index_1", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
"ProvisionedThroughput": {"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
},
{
"IndexName": "gsi-2",
"KeySchema": [{"AttributeName": "secondary_index_2", "KeyType": "HASH"}],
"Projection": {"ProjectionType": "ALL"},
"ProvisionedThroughput": {"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
},
],
AttributeDefinitions=[
{"AttributeName": name, "AttributeType": value["type"]}
for name, value in list(TEST_INDEX.items()) + list(SECONDARY_INDEX.items())
],
ProvisionedThroughput={"ReadCapacityUnits": 100, "WriteCapacityUnits": 100},
)
yield
ddb.delete_table(TableName=TEST_TABLE_NAME)
mock_dynamodb2().stop()
示例14: mock_metastore
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def mock_metastore():
with mock_dynamodb2():
metastore, table_name = build_metastore()
yield metastore
delete_metastore(table_name)
示例15: dynamodb_mock
# 需要导入模块: import moto [as 别名]
# 或者: from moto import mock_dynamodb2 [as 别名]
def dynamodb_mock():
import moto
with moto.mock_dynamodb2():
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
create_users_table(dynamodb)
yield dynamodb