File: test_paginator.py

package info (click to toggle)
python-botocore 1.37.9%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 121,768 kB
  • sloc: python: 73,696; xml: 14,880; javascript: 181; makefile: 155
file content (104 lines) | stat: -rw-r--r-- 4,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from botocore.docs.paginator import PaginatorDocumenter
from botocore.paginate import PaginatorModel
from tests.unit.docs import BaseDocsTest


class TestPaginatorDocumenter(BaseDocsTest):
    def setUp(self):
        super().setUp()
        self.add_shape_to_params('Biz', 'String')
        self.extra_setup()

    def extra_setup(self):
        self.setup_client()
        paginator_model = PaginatorModel(self.paginator_json_model)
        self.paginator_documenter = PaginatorDocumenter(
            client=self.client,
            service_paginator_model=paginator_model,
            root_docs_path=self.root_services_path,
        )

    def test_document_paginators(self):
        self.paginator_documenter.document_paginators(self.doc_structure)
        self.assert_contains_lines_in_order(
            [
                '==========',
                'Paginators',
                '==========',
                'The available paginators are:',
                'paginator/SampleOperation',
            ]
        )
        self.assert_contains_lines_in_order(
            [
                '.. py:class:: MyService.Paginator.SampleOperation',
                '  ::',
                '    paginator = client.get_paginator(\'sample_operation\')',
                '  .. py:method:: paginate(**kwargs)',
                (
                    '    Creates an iterator that will paginate through responses'
                    ' from :py:meth:`MyService.Client.sample_operation`.'
                ),
                '    **Request Syntax**',
                '    ::',
                '      response_iterator = paginator.paginate(',
                '          Biz=\'string\',',
                '          PaginationConfig={',
                '              \'MaxItems\': 123,',
                '              \'PageSize\': 123,',
                '              \'StartingToken\': \'string\'',
                '          }',
                '      )',
                '    :type Biz: string',
                '    :param Biz:',
                '    :type PaginationConfig: dict',
                '    :param PaginationConfig:',
                (
                    '      A dictionary that provides parameters to '
                    'control pagination.'
                ),
                '      - **MaxItems** *(integer) --*',
                '      - **PageSize** *(integer) --*',
                '      - **StartingToken** *(string) --*',
                '    :rtype: dict',
                '    :returns:',
                '      **Response Syntax**',
                '      ::',
                '        {',
                '            \'Biz\': \'string\',',
                '            \'NextToken\': \'string\'',
                '        }',
                '      **Response Structure**',
                '      - *(dict) --*',
                '        - **Biz** *(string) --*',
                '        - **NextToken** *(string) --*',
            ],
            self.get_nested_service_contents(
                'myservice', 'paginator', 'SampleOperation'
            ),
        )

    def test_no_page_size_if_no_limit_key(self):
        paginator = self.paginator_json_model["pagination"]
        operation = paginator["SampleOperation"]
        del operation["limit_key"]

        self.paginator_documenter.document_paginators(self.doc_structure)
        self.assert_not_contains_lines(
            [
                '              \'PageSize\': 123,',
                '      - **PageSize** *(integer) --*',
            ]
        )