File: test_convert_parameters.py

package info (click to toggle)
sphinxcontrib-openapi 0.8.4-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 880 kB
  • sloc: python: 7,575; makefile: 23
file content (100 lines) | stat: -rw-r--r-- 2,297 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
""".convert_parameters() test suite."""

import pytest

import sphinxcontrib.openapi._lib2to3 as lib2to3


_MISSING = object()


@pytest.fixture(scope="function")
def convert_parameters(oas_fragment):
    def _wrapper(parameters):
        oas2 = oas_fragment(
            """
            swagger: "2.0"
            info:
              title: An example spec
              version: "1.0"
            paths:
              /test:
                get:
                  responses:
                    '200':
                      description: a response description
            """
        )
        oas2["paths"]["/test"]["get"]["parameters"] = parameters

        oas3 = lib2to3.convert(oas2)
        return oas3["paths"]["/test"]["get"].get("parameters", _MISSING)

    return _wrapper


def test_header_path_query(convert_parameters, oas_fragment):
    converted = convert_parameters(
        oas_fragment(
            """
            - in: header
              name: token
              type: string
            - in: path
              name: username
              required: true
              type: string
            - in: query
              name: id
              type: string
            """
        ),
    )
    assert converted == oas_fragment(
        """
        - in: header
          name: token
          schema:
            type: string
        - in: path
          name: username
          required: true
          schema:
            type: string
        - in: query
          name: id
          schema:
            type: string
        """
    )


def test_body_is_ignored(convert_parameters, oas_fragment):
    converted = convert_parameters(
        oas_fragment(
            """
            - description: user to add to the system
              in: body
              name: user
              required: true
              schema:
                $ref: '#/definitions/User'
            """
        ),
    )
    assert converted is _MISSING


def test_formData_is_ignored(convert_parameters, oas_fragment):
    converted = convert_parameters(
        oas_fragment(
            """
            - description: The avatar of the user
              in: formData
              name: avatar
              type: file
            """
        ),
    )

    assert converted is _MISSING