当前位置: 首页>>代码示例>>Python>>正文


Python connection.TableConnection类代码示例

本文整理汇总了Python中pynamodb.connection.TableConnection的典型用法代码示例。如果您正苦于以下问题:Python TableConnection类的具体用法?Python TableConnection怎么用?Python TableConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TableConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_batch_get_item

    def test_batch_get_item(self):
        """
        TableConnection.batch_get_item
        """
        items = []
        conn = TableConnection(self.test_table_name)
        for i in range(10):
            items.append({"ForumName": "FooForum", "Subject": "thread-{0}".format(i)})
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.batch_get_item(items)
            params = {
                "ReturnConsumedCapacity": "TOTAL",
                "RequestItems": {
                    self.test_table_name: {
                        "Keys": [
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-0"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-1"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-2"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-3"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-4"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-5"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-6"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-7"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-8"}},
                            {"ForumName": {"S": "FooForum"}, "Subject": {"S": "thread-9"}},
                        ]
                    }
                },
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:35,代码来源:test_table_connection.py

示例2: test_delete_item

    def test_delete_item(self):
        """
        TableConnection.delete_item
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.delete_item(
                "Amazon DynamoDB",
                "How do I update multiple items?")
            params = {
                'ReturnConsumedCapacity': 'TOTAL',
                'Key': {
                    'ForumName': {
                        'S': 'Amazon DynamoDB'
                    },
                    'Subject': {
                        'S': 'How do I update multiple items?'
                    }
                },
                'TableName': self.test_table_name
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:BCVisin,项目名称:PynamoDB,代码行数:27,代码来源:test_table_connection.py

示例3: test_query

 def test_query(self):
     """
     TableConnection.query
     """
     conn = TableConnection(self.test_table_name)
     with patch(PATCH_METHOD) as req:
         req.return_value = DESCRIBE_TABLE_DATA
         conn.describe_table()
     with patch(PATCH_METHOD) as req:
         req.return_value = {}
         conn.query(
             "FooForum",
             key_conditions={'ForumName': {'ComparisonOperator': 'BEGINS_WITH', 'AttributeValueList': ['thread']}}
         )
         params = {
             'ReturnConsumedCapacity': 'TOTAL',
             'KeyConditions': {
                 'ForumName': {
                     'ComparisonOperator': 'BEGINS_WITH', 'AttributeValueList': [{
                         'S': 'thread'
                     }]
                 }
             },
             'TableName': self.test_table_name
         }
         self.assertEqual(req.call_args[0][1], params)
开发者ID:BCVisin,项目名称:PynamoDB,代码行数:26,代码来源:test_table_connection.py

示例4: test_query

 def test_query(self):
     """
     TableConnection.query
     """
     conn = TableConnection(self.test_table_name)
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), DESCRIBE_TABLE_DATA
         conn.describe_table()
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), {}
         conn.query(
             "FooForum",
             key_conditions={'ForumName': {'ComparisonOperator': 'BEGINS_WITH', 'AttributeValueList': ['thread']}},
             exclusive_start_key="test_start_key"
         )
         params = {
             'return_consumed_capacity': 'TOTAL',
             'key_conditions': {
                 'ForumName': {
                     'ComparisonOperator': 'BEGINS_WITH', 'AttributeValueList': [{
                         'S': 'thread'
                     }]
                 }
             },
             'table_name': self.test_table_name,
             'exclusive_start_key': {'ForumName': {'S': 'test_start_key'}}
         }
         self.assertEqual(req.call_args[1], params)
开发者ID:mpresh,项目名称:PynamoDB,代码行数:28,代码来源:test_table_connection.py

示例5: test_create_table

 def test_create_table(self):
     """
     TableConnection.create_table
     """
     conn = TableConnection(self.test_table_name)
     kwargs = {"read_capacity_units": 1, "write_capacity_units": 1}
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs["attribute_definitions"] = [
         {"attribute_name": "key1", "attribute_type": "S"},
         {"attribute_name": "key2", "attribute_type": "S"},
     ]
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs["key_schema"] = [
         {"attribute_name": "key1", "key_type": "hash"},
         {"attribute_name": "key2", "key_type": "range"},
     ]
     params = {
         "TableName": "ci-table",
         "ProvisionedThroughput": {"WriteCapacityUnits": 1, "ReadCapacityUnits": 1},
         "AttributeDefinitions": [
             {"AttributeType": "S", "AttributeName": "key1"},
             {"AttributeType": "S", "AttributeName": "key2"},
         ],
         "KeySchema": [{"KeyType": "HASH", "AttributeName": "key1"}, {"KeyType": "RANGE", "AttributeName": "key2"}],
     }
     with patch(PATCH_METHOD) as req:
         req.return_value = {}
         conn.create_table(**kwargs)
         kwargs = req.call_args[0][1]
         self.assertEqual(kwargs, params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:30,代码来源:test_table_connection.py

示例6: test_describe_table

 def test_describe_table(self):
     """
     TableConnection.describe_table
     """
     with patch(PATCH_METHOD) as req:
         req.return_value = DESCRIBE_TABLE_DATA
         conn = TableConnection(self.test_table_name)
         conn.describe_table()
         self.assertEqual(conn.table_name, self.test_table_name)
         self.assertEqual(req.call_args[0][1], {"TableName": "ci-table"})
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:10,代码来源:test_table_connection.py

示例7: test_delete_table

 def test_delete_table(self):
     """
     TableConnection.delete_table
     """
     params = {"TableName": "ci-table"}
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), None
         conn = TableConnection(self.test_table_name)
         conn.delete_table()
         kwargs = req.call_args[0][1]
         self.assertEqual(kwargs, params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:11,代码来源:test_table_connection.py

示例8: test_get_item

    def test_get_item(self):
        """
        TableConnection.get_item
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = GET_ITEM_DATA
            item = conn.get_item("Amazon DynamoDB", "How do I update multiple items?")
            self.assertEqual(item, GET_ITEM_DATA)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:13,代码来源:test_table_connection.py

示例9: test_scan

 def test_scan(self):
     """
     TableConnection.scan
     """
     conn = TableConnection(self.test_table_name)
     with patch(PATCH_METHOD) as req:
         req.return_value = DESCRIBE_TABLE_DATA
         conn.describe_table()
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), {}
         conn.scan()
         params = {"ReturnConsumedCapacity": "TOTAL", "TableName": self.test_table_name}
         self.assertEqual(req.call_args[0][1], params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:13,代码来源:test_table_connection.py

示例10: test_scan

 def test_scan(self):
     """
     TableConnection.scan
     """
     conn = TableConnection(self.test_table_name)
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), DESCRIBE_TABLE_DATA
         conn.describe_table()
     with patch(PATCH_METHOD) as req:
         req.return_value = HttpOK(), {}
         conn.scan()
         params = {
             'return_consumed_capacity': 'TOTAL',
             'table_name': self.test_table_name
         }
         self.assertEqual(req.call_args[1], params)
开发者ID:BalanceCareerInc,项目名称:PynamoDB,代码行数:16,代码来源:test_table_connection.py

示例11: test_update_item

    def test_update_item(self):
        """
        TableConnection.update_item
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        attr_updates = {
            'Subject': {
                'Value': 'foo-subject',
                'Action': 'PUT'
            },
        }

        with patch(PATCH_METHOD) as req:
            req.return_value = HttpOK(), {}
            conn.update_item(
                'foo-key',
                attribute_updates=attr_updates,
                range_key='foo-range-key',
            )
            params = {
                'Key': {
                    'ForumName': {
                        'S': 'foo-key'
                    },
                    'Subject': {
                        'S': 'foo-range-key'
                    }
                },
                'UpdateExpression': 'SET #0 = :0',
                'ExpressionAttributeNames': {
                    '#0': 'Subject'
                },
                'ExpressionAttributeValues': {
                    ':0': {
                        'S': 'foo-subject'
                    }
                },
                'ReturnConsumedCapacity': 'TOTAL',
                'TableName': 'ci-table'
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:eukaryote,项目名称:PynamoDB,代码行数:45,代码来源:test_table_connection.py

示例12: test_delete_item

    def test_delete_item(self):
        """
        TableConnection.delete_item
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.delete_item("Amazon DynamoDB", "How do I update multiple items?")
            params = {
                "ReturnConsumedCapacity": "TOTAL",
                "Key": {"ForumName": {"S": "Amazon DynamoDB"}, "Subject": {"S": "How do I update multiple items?"}},
                "TableName": self.test_table_name,
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:18,代码来源:test_table_connection.py

示例13: test_rate_limited_scan

 def test_rate_limited_scan(self):
     """
     TableConnection.rate_limited_scan
     """
     conn = TableConnection(self.test_table_name)
     with patch('pynamodb.connection.Connection.rate_limited_scan') as req:
         req.return_value = {}
         conn.rate_limited_scan(attributes_to_get='attributes_to_get',
             page_size=1,
             limit=2,
             conditional_operator='AND',
             scan_filter={'filter': 'X'},
             segment=2,
             total_segments=4,
             exclusive_start_key='EX',
             timeout_seconds=11,
             read_capacity_to_consume_per_second=12,
             allow_rate_limited_scan_without_consumed_capacity=False,
             max_sleep_between_retry=3,
             max_consecutive_exceptions=7,
             consistent_read=True,
             index_name='index'
         )
         self.assertEqual(self.test_table_name, req.call_args[0][0])
         params = {
             'filter_condition': None,
             'attributes_to_get': 'attributes_to_get',
             'page_size': 1,
             'limit': 2,
             'conditional_operator': 'AND',
             'scan_filter': {'filter': 'X'},
             'segment': 2,
             'total_segments': 4,
             'exclusive_start_key': 'EX',
             'timeout_seconds': 11,
             'read_capacity_to_consume_per_second': 12,
             'allow_rate_limited_scan_without_consumed_capacity': False,
             'max_sleep_between_retry': 3,
             'max_consecutive_exceptions': 7,
             'consistent_read': True,
             'index_name': 'index'
         }
         self.assertEqual(params, req.call_args[1])
开发者ID:jlafon,项目名称:PynamoDB,代码行数:43,代码来源:test_table_connection.py

示例14: test_query

    def test_query(self):
        """
        TableConnection.query
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.query(
                "FooForum",
                Path('Subject').startswith('thread')
            )
            params = {
                'ReturnConsumedCapacity': 'TOTAL',
                'KeyConditionExpression': '(#0 = :0 AND begins_with (#1, :1))',
                'ExpressionAttributeNames': {
                    '#0': 'ForumName',
                    '#1': 'Subject'
                },
                'ExpressionAttributeValues': {
                    ':0': {
                        'S': 'FooForum'
                    },
                    ':1': {
                        'S': 'thread'
                    }
                },
                'TableName': self.test_table_name
            }
            self.assertEqual(req.call_args[0][1], params)

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.query(
                "FooForum",
                key_conditions={'Subject': {'ComparisonOperator': 'BEGINS_WITH', 'AttributeValueList': ['thread']}}
            )
            params = {
                'ReturnConsumedCapacity': 'TOTAL',
                'KeyConditionExpression': '(#0 = :0 AND begins_with (#1, :1))',
                'ExpressionAttributeNames': {
                    '#0': 'ForumName',
                    '#1': 'Subject'
                },
                'ExpressionAttributeValues': {
                    ':0': {
                        'S': 'FooForum'
                    },
                    ':1': {
                        'S': 'thread'
                    }
                },
                'TableName': self.test_table_name
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:eukaryote,项目名称:PynamoDB,代码行数:58,代码来源:test_table_connection.py

示例15: test_put_item

    def test_put_item(self):
        """
        TableConnection.put_item
        """
        conn = TableConnection(self.test_table_name)
        with patch(PATCH_METHOD) as req:
            req.return_value = DESCRIBE_TABLE_DATA
            conn.describe_table()

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.put_item("foo-key", range_key="foo-range-key", attributes={"ForumName": "foo-value"})
            params = {
                "ReturnConsumedCapacity": "TOTAL",
                "TableName": self.test_table_name,
                "Item": {"ForumName": {"S": "foo-value"}, "Subject": {"S": "foo-range-key"}},
            }
            self.assertEqual(req.call_args[0][1], params)

        with patch(PATCH_METHOD) as req:
            req.return_value = {}
            conn.put_item("foo-key", range_key="foo-range-key", attributes={"ForumName": "foo-value"})
            params = {
                "ReturnConsumedCapacity": "TOTAL",
                "Item": {"ForumName": {"S": "foo-value"}, "Subject": {"S": "foo-range-key"}},
                "TableName": self.test_table_name,
            }
            self.assertEqual(req.call_args[0][1], params)

        with patch(PATCH_METHOD) as req:
            req.return_value = HttpOK(), {}
            conn.put_item(
                "foo-key",
                range_key="foo-range-key",
                attributes={"ForumName": "foo-value"},
                conditional_operator="and",
                expected={"ForumName": {"Exists": False}},
            )
            params = {
                "ReturnConsumedCapacity": "TOTAL",
                "Item": {"ForumName": {"S": "foo-value"}, "Subject": {"S": "foo-range-key"}},
                "TableName": self.test_table_name,
                "ConditionalOperator": "AND",
                "Expected": {"ForumName": {"Exists": False}},
            }
            self.assertEqual(req.call_args[0][1], params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:46,代码来源:test_table_connection.py


注:本文中的pynamodb.connection.TableConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。