Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/dynamodb/test_pagination.py
1567 views
1
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import json
14
15
from awscli.testutils import BaseAWSCommandParamsTest
16
17
18
class TestPagination(BaseAWSCommandParamsTest):
19
def setUp(self):
20
super(TestPagination, self).setUp()
21
self.first_response = {
22
"Items": [{"Key": {"B": "MjEzNw=="}}],
23
"Count": 1,
24
"ScannedCount": 1,
25
"ConsumedCapacity": 1,
26
"LastEvaluatedKey": {"Key": {"B":"MjEzNw=="}}
27
}
28
self.second_response = {
29
"Items": [],
30
"Count": 0,
31
"ScannedCount": 1,
32
"ConsumedCapacity": 1
33
}
34
35
def test_scan_pagination_binary_last_evaluated_key(self):
36
self.parsed_responses = [self.first_response, self.second_response]
37
self.run_cmd('dynamodb scan --table-name test', expected_rc=0)
38
self.assertEqual(len(self.operations_called), 2)
39
# The start key in the second request should have been parsed to binary
40
sent_start_key = self.operations_called[1][1].get('ExclusiveStartKey')
41
expected_start_key = {"Key": {"B": b'2137'}}
42
self.assertEqual(sent_start_key, expected_start_key)
43
44
def test_pagination_disabled_works(self):
45
self.parsed_responses = [self.first_response]
46
cmd = 'dynamodb scan --table-name table --no-paginate --output json'
47
stdout, _, _ = self.run_cmd(cmd, expected_rc=0)
48
# Ensure the base64 encoded last evaluated key is in stdout
49
self.assertIn('"MjEzNw=="', stdout)
50
51