コード例 #1
0
    def setup(self):
        self.mocks = [mock_dynamodb(), mock_dynamodbstreams()]
        for m in self.mocks:
            m.start()

        # create a table with a stream
        conn = boto3.client("dynamodb", region_name="us-east-1")

        resp = conn.create_table(
            TableName="test-streams",
            KeySchema=[{
                "AttributeName": "id",
                "KeyType": "HASH"
            }],
            AttributeDefinitions=[{
                "AttributeName": "id",
                "AttributeType": "S"
            }],
            ProvisionedThroughput={
                "ReadCapacityUnits": 1,
                "WriteCapacityUnits": 1
            },
            StreamSpecification={
                "StreamEnabled": True,
                "StreamViewType": "NEW_AND_OLD_IMAGES",
            },
        )
        self.stream_arn = resp["TableDescription"]["LatestStreamArn"]
コード例 #2
0
def test_xray_dynamo_request_id_with_context_mgr():
    with mock_xray_client():
        assert isinstance(xray_core.xray_recorder._emitter, MockEmitter)
        with mock_dynamodb():
            # Could be ran in any order, so we need to tell sdk that its been unpatched
            xray_core_patcher._PATCHED_MODULES = set()
            xray_core.patch_all()

            client = boto3.client("dynamodb", region_name="us-east-1")

            with XRaySegment():
                resp = client.list_tables()
                resp["ResponseMetadata"].should.contain("RequestId")
                id1 = resp["ResponseMetadata"]["RequestId"]

            with XRaySegment():
                client.list_tables()
                resp = client.list_tables()
                id2 = resp["ResponseMetadata"]["RequestId"]

            id1.should_not.equal(id2)

            setattr(botocore.client.BaseClient, "_make_api_call",
                    original_make_api_call)
            setattr(botocore.endpoint.Endpoint, "_encode_headers",
                    original_encode_headers)
            setattr(requests.Session, "request", original_session_request)
            setattr(requests.Session, "prepare_request",
                    original_session_prep_request)

    # Verify we have unmocked the xray recorder
    assert not isinstance(xray_core.xray_recorder._emitter, MockEmitter)
コード例 #3
0
ファイル: test_duo.py プロジェクト: eykd/duo
    def setUp(self):
        super(DynamoDBTests, self).setUp()
        for key, value in iteritems(self.default_item_data):
            setattr(self, key, value)

        self.dynamo_patcher = moto.mock_dynamodb()
        self.dynamo_patcher.start()

        import duo
        self.duo = duo
        self.db = duo.DynamoDB(key=self.key, secret=self.secret)
        self.schema = self.db.connection.create_schema(
            hash_key_name=self.hash_key_name,
            hash_key_proto_value=str,
            range_key_name=self.range_key_name,
            range_key_proto_value=str,
        )
        self.db.connection.create_table(self.table_name, self.schema, 10, 10)
 def set_up(self):
     self.mock_dynamodb = mock_dynamodb().start()
     dynamodb_client = boto3.client("dynamodb")
     dynamodb_client.create_table(AttributeDefinitions=[{
         'AttributeName': 'col_id',
         'AttributeType': 'N'
     }, {
         'AttributeName': 'first_name',
         'AttributeType': 'S'
     }, {
         'AttributeName': 'last_name',
         'AttributeType': 'S'
     }],
                                  TableName='TestTable',
                                  KeySchema=[{
                                      'AttributeName': 'col_id',
                                      'KeyType': 'HASH'
                                  }])
     yield "Connected"
     print("Teardown...")
     self.mock_dynamodb.stop()
コード例 #5
0
 def setup(self):
     self.mocks = [mock_dynamodb(), mock_dynamodbstreams()]
     for m in self.mocks:
         m.start()
コード例 #6
0
ファイル: test_dynamodb.py プロジェクト: tmwong2003/moto
def test_deprecation_warning():
    with pytest.warns(None) as record:
        mock_dynamodb()
    str(record[0].message).should.contain(
        "Module mock_dynamodb has been deprecated, and will be repurposed in a later release"
    )
コード例 #7
0
def dynamodb():
    with mock_dynamodb():
        yield boto3.resource('dynamodb')
コード例 #8
0
ファイル: test_server.py プロジェクト: tmwong2003/moto
def test_client():
    with mock_dynamodb():
        backend = server.create_backend_app("dynamodb")
        test_client = backend.test_client()

        yield test_client