Python moto.mock_dynamodb2() Examples
The following are 22
code examples of moto.mock_dynamodb2().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
moto
, or try the search function
.
Example #1
Source File: test_core.py From streamalert with Apache License 2.0 | 7 votes |
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 )
Example #2
Source File: test_driver_dynamodb.py From streamalert with Apache License 2.0 | 6 votes |
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()
Example #3
Source File: test_driver_dynamodb.py From streamalert with Apache License 2.0 | 6 votes |
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._int_driver = construct_persistence_driver( self.config['lookup_tables']['tables']['dinosaur_multi_int'] ) self._string_driver = construct_persistence_driver( self.config['lookup_tables']['tables']['dinosaur_multi_string'] ) self._dict_driver = construct_persistence_driver( self.config['lookup_tables']['tables']['dinosaur_multi_dict'] ) self._put_mock_tables()
Example #4
Source File: test_alert_table.py From streamalert with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: functional_test_utils.py From aws-dynamodb-encryption-python with Apache License 2.0 | 6 votes |
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()
Example #6
Source File: conftest.py From swag-client with Apache License 2.0 | 5 votes |
def dynamodb(aws_credentials): with mock_dynamodb2(): yield boto3.resource('dynamodb', region_name='us-east-1')
Example #7
Source File: test_boto3.py From opentracing-python-instrumentation with MIT License | 5 votes |
def dynamodb_mock(): import moto with moto.mock_dynamodb2(): dynamodb = boto3.resource('dynamodb', region_name='us-east-1') create_users_table(dynamodb) yield dynamodb
Example #8
Source File: functional_test_utils.py From aws-dynamodb-encryption-python with Apache License 2.0 | 5 votes |
def mock_metastore(): with mock_dynamodb2(): metastore, table_name = build_metastore() yield metastore delete_metastore(table_name)
Example #9
Source File: functional_test_utils.py From aws-dynamodb-encryption-python with Apache License 2.0 | 5 votes |
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()
Example #10
Source File: functional_test_utils.py From aws-dynamodb-encryption-python with Apache License 2.0 | 5 votes |
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()
Example #11
Source File: conftest.py From cc_dynamodb3 with MIT License | 5 votes |
def mock_db(request): """We never want to use the real dynamodb.""" mock = mock_dynamodb2() mock.start() request.addfinalizer(mock.stop)
Example #12
Source File: test_dynamodb.py From aws-auto-cleanup with GNU General Public License v3.0 | 5 votes |
def test_class(self): with moto.mock_dynamodb2(): whitelist = {"dynamodb": {"table": ["settings-table"]}} 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
Example #13
Source File: test_dynamodb.py From aws-auto-cleanup with GNU General Public License v3.0 | 5 votes |
def test_class(self): with moto.mock_dynamodb2(): whitelist = {} settings = { "general": {"dry_run": False}, "services": {"dynamodb": {"tables": {"clean": True, "ttl": 7}}}, } resource_tree = {"AWS": {}} test_class = dynamodb_cleanup.DynamoDBCleanup( logging, whitelist, settings, resource_tree, "ap-southeast-2" ) yield test_class
Example #14
Source File: test_dynamodb.py From aws-auto-cleanup with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: test_setup.py From aws-auto-remediate with GNU General Public License v3.0 | 5 votes |
def setup(self): with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts(): setup = lambda_handler.Setup(logging) yield setup
Example #16
Source File: test_promoter.py From streamalert with Apache License 2.0 | 5 votes |
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()
Example #17
Source File: test_rule_table.py From streamalert with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: tests.py From handson-labs-2018 with MIT License | 5 votes |
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)
Example #19
Source File: test_setup.py From aws-auto-remediate with GNU General Public License v3.0 | 5 votes |
def setup(self): with moto.mock_dynamodb2(), moto.mock_sts(): setup = lambda_handler.Setup(logging) yield setup
Example #20
Source File: test_setup.py From aws-auto-remediate with GNU General Public License v3.0 | 5 votes |
def setup(self): with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts(): setup = lambda_handler.Setup(logging) yield setup
Example #21
Source File: test_setup.py From aws-auto-remediate with GNU General Public License v3.0 | 5 votes |
def setup(self): with moto.mock_cloudformation(), moto.mock_dynamodb2(), moto.mock_sts(): setup = lambda_handler.Setup(logging) yield setup
Example #22
Source File: autoscaler.py From clusterman with Apache License 2.0 | 4 votes |
def autoscaler_patches(context): behave.use_fixture(boto_patches, context) rg1 = mock.Mock(spec=SpotFleetResourceGroup, id='rg1', target_capacity=10, fulfilled_capacity=10, is_stale=False, min_capacity=0, max_capacity=float('inf')) rg2 = mock.Mock(spec=SpotFleetResourceGroup, id='rg2', target_capacity=10, fulfilled_capacity=10, is_stale=False, min_capacity=0, max_capacity=float('inf')) resource_totals = {'cpus': 80, 'mem': 1000, 'disk': 1000, 'gpus': 0} with staticconf.testing.PatchConfiguration( {'autoscaling': {'default_signal_role': 'bar'}}, ), mock.patch( 'clusterman.autoscaler.autoscaler.get_monitoring_client', ), mock.patch( 'clusterman.aws.util.SpotFleetResourceGroup.load', return_value={rg1.id: rg1, rg2.id: rg2}, ), mock.patch( 'clusterman.autoscaler.pool_manager.PoolManager', wraps=PoolManager, ), mock.patch( 'clusterman.autoscaler.autoscaler.PoolManager.prune_excess_fulfilled_capacity', ), mock.patch( 'clusterman.autoscaler.pool_manager.ClusterConnector.load', ) as mock_cluster_connector, mock.patch( 'clusterman.autoscaler.autoscaler.PoolManager._calculate_non_orphan_fulfilled_capacity', return_value=20, ), mock.patch( 'clusterman.autoscaler.signals.Signal._connect_to_signal_process', ), mock.patch( 'clusterman.autoscaler.autoscaler.Signal._get_metrics', ) as mock_metrics, mock_dynamodb2(): dynamodb.create_table( TableName=CLUSTERMAN_STATE_TABLE, KeySchema=[ {'AttributeName': 'state', 'KeyType': 'HASH'}, {'AttributeName': 'entity', 'KeyType': 'SORT'}, ], AttributeDefinitions=[ {'AttributeName': 'state', 'AttributeType': 'S'}, {'AttributeName': 'entity', 'AttributeType': 'S'}, ], ) mock_metrics.return_value = {} # don't know why this is necessary but we get flaky tests if it's not set mock_cluster_connector.return_value.get_resource_total.side_effect = resource_totals.__getitem__ yield