File: test_render_request_body.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 (107 lines) | stat: -rw-r--r-- 2,605 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
105
106
107
"""OpenAPI spec renderer: render_request_body."""

import textwrap

import pytest

from sphinxcontrib.openapi import renderers


def textify(generator):
    return "\n".join(generator)


@pytest.mark.parametrize(
    "content_type", ["application/json", "application/foobar+json"]
)
def test_render_request_body_schema_description(
    testrenderer, oas_fragment, content_type
):
    """JSON schema description is rendered."""

    markup = textify(
        testrenderer.render_request_body(
            oas_fragment(
                f"""
                content:
                  {content_type}:
                    schema:
                      properties:
                        foo:
                          type: string
                        bar:
                          type: integer
                """
            ),
            "/evidences/{evidenceId}",
            "POST",
        )
    )
    assert markup == textwrap.dedent(
        """\
        :reqjson foo:
        :reqjsonobj foo: string
        :reqjson bar:
        :reqjsonobj bar: integer

        """
    )


def test_render_request_body_schema_description_non_json(testrenderer, oas_fragment):
    """JSON schema is not rendered for non JSON mimetype."""

    markup = textify(
        testrenderer.render_request_body(
            oas_fragment(
                """
                content:
                  text/csv:
                    schema:
                      properties:
                        foo:
                          type: string
                        bar:
                          type: integer
                """
            ),
            "/evidences/{evidenceId}",
            "POST",
        )
    )
    assert markup == textwrap.dedent(
        """\
        """
    )


def test_render_request_body_schema_description_turned_off(fakestate, oas_fragment):
    """JSON schema description is not rendered b/c feature is off."""

    testrenderer = renderers.HttpdomainRenderer(
        fakestate,
        {"no-json-schema-description": True},
    )

    markup = textify(
        testrenderer.render_request_body(
            oas_fragment(
                """
                content:
                  application/json:
                    schema:
                      properties:
                        foo:
                          type: string
                        bar:
                          type: integer
                """
            ),
            "/evidences/{evidenceId}",
            "POST",
        )
    )
    assert markup == textwrap.dedent(
        """\
        """
    )