Skip to content

Commit

Permalink
render_response_content -> render_response_example
Browse files Browse the repository at this point in the history
Because it's what it actually does! Moreover, I even use '_example'
suffix in the similar situation for request body's example, and I am
about to add another rendering method that also deals with content but
leaves alone example.
  • Loading branch information
ikalnytskyi committed Aug 29, 2020
1 parent 7de882b commit 4e08f1a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions sphinxcontrib/openapi/renderers/_httpdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def render_response(self, status_code, response):
if "content" in response and status_code in self._response_examples_for:
yield ""
yield from indented(
self.render_response_content(response["content"], status_code)
self.render_response_example(response["content"], status_code)
)

if "headers" in response:
Expand Down Expand Up @@ -362,7 +362,7 @@ def render_response(self, status_code, response):
markers = ", ".join(markers)
yield f":resheadertype {header_name}: {markers}"

def render_response_content(self, media_type, status_code):
def render_response_example(self, media_type, status_code):
# OpenAPI 3.0 spec may contain more than one response media type, and
# each media type may contain more than one example. Rendering all
# invariants normally is not an option because the result will be hard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""OpenAPI spec renderer: render_response_content."""
"""OpenAPI spec renderer: render_response_example."""

import textwrap

Expand Down Expand Up @@ -109,11 +109,11 @@ def textify(generator):
),
],
)
def test_render_response_content_example(testrenderer, oas_fragment, media_type):
def test_render_response_example(testrenderer, oas_fragment, media_type):
"""Path response's example is rendered."""

markup = textify(
testrenderer.render_response_content(oas_fragment(media_type), "200")
testrenderer.render_response_example(oas_fragment(media_type), "200")
)
assert markup == textwrap.dedent(
"""\
Expand All @@ -130,11 +130,11 @@ def test_render_response_content_example(testrenderer, oas_fragment, media_type)
)


def test_render_response_content_example_1st_from_examples(testrenderer, oas_fragment):
def test_render_response_example_1st_from_examples(testrenderer, oas_fragment):
"""Path response's first example is rendered."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand Down Expand Up @@ -166,13 +166,11 @@ def test_render_response_content_example_1st_from_examples(testrenderer, oas_fra
)


def test_render_response_content_example_1st_from_media_type(
testrenderer, oas_fragment
):
def test_render_response_example_1st_from_media_type(testrenderer, oas_fragment):
"""Path response's example from first media type is rendered."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/plain:
Expand Down Expand Up @@ -205,7 +203,7 @@ def test_render_response_content_example_1st_from_media_type(
["example_preference_key"],
[pytest.param("response-example-preference"), pytest.param("example-preference")],
)
def test_render_response_content_example_preference(
def test_render_response_example_preference(
fakestate, example_preference_key, oas_fragment
):
"""Path response's example from preferred media type is rendered."""
Expand All @@ -215,7 +213,7 @@ def test_render_response_content_example_preference(
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand Down Expand Up @@ -249,7 +247,7 @@ def test_render_response_content_example_preference(
["example_preference_key"],
[pytest.param("response-example-preference"), pytest.param("example-preference")],
)
def test_render_response_content_example_preference_complex(
def test_render_response_example_preference_complex(
fakestate, example_preference_key, oas_fragment
):
"""Path response's example from preferred media type is rendered."""
Expand All @@ -259,7 +257,7 @@ def test_render_response_content_example_preference_complex(
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand Down Expand Up @@ -292,7 +290,7 @@ def test_render_response_content_example_preference_complex(
)


def test_render_response_content_example_preference_priority(fakestate, oas_fragment):
def test_render_response_example_preference_priority(fakestate, oas_fragment):
"""Path response's example from preferred media type is rendered."""

testrenderer = renderers.HttpdomainRenderer(
Expand All @@ -304,7 +302,7 @@ def test_render_response_content_example_preference_priority(fakestate, oas_frag
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand Down Expand Up @@ -335,7 +333,7 @@ def test_render_response_content_example_preference_priority(fakestate, oas_frag


@responses.activate
def test_render_response_content_example_external(testrenderer, oas_fragment):
def test_render_response_example_external(testrenderer, oas_fragment):
"""Path response's example can be retrieved from external location."""

responses.add(
Expand All @@ -346,7 +344,7 @@ def test_render_response_content_example_external(testrenderer, oas_fragment):
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand All @@ -371,7 +369,7 @@ def test_render_response_content_example_external(testrenderer, oas_fragment):


@responses.activate
def test_render_response_content_example_external_errored_next_example(
def test_render_response_example_external_errored_next_example(
testrenderer, caplog, oas_fragment
):
"""Path response's example fallbacks on next when external cannot be retrieved."""
Expand All @@ -381,7 +379,7 @@ def test_render_response_content_example_external_errored_next_example(
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand All @@ -408,7 +406,7 @@ def test_render_response_content_example_external_errored_next_example(


@responses.activate
def test_render_response_content_example_external_errored_next_media_type(
def test_render_response_example_external_errored_next_media_type(
testrenderer, oas_fragment, caplog
):
"""Path response's example fallbacks on next when external cannot be retrieved."""
Expand All @@ -418,7 +416,7 @@ def test_render_response_content_example_external_errored_next_media_type(
)

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand All @@ -444,11 +442,11 @@ def test_render_response_content_example_external_errored_next_media_type(
)


def test_render_response_content_example_content_type(testrenderer, oas_fragment):
def test_render_response_example_content_type(testrenderer, oas_fragment):
"""Path response's example can render something other than application/json."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand All @@ -473,11 +471,11 @@ def test_render_response_content_example_content_type(testrenderer, oas_fragment
)


def test_render_response_content_example_noop(testrenderer, oas_fragment):
def test_render_response_example_noop(testrenderer, oas_fragment):
"""Path response's example is not rendered if there's nothing to render."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
application/json:
Expand All @@ -500,13 +498,13 @@ def test_render_response_content_example_noop(testrenderer, oas_fragment):
pytest.param("422", "Unprocessable Entity", id="422"),
],
)
def test_render_response_content_status_code(
def test_render_response_status_code(
testrenderer, oas_fragment, status_code, status_text
):
"""Path response's example is rendered with proper status code."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand Down Expand Up @@ -539,13 +537,13 @@ def test_render_response_content_status_code(
pytest.param("4XX", "400", "Bad Request", id="4XX"),
],
)
def test_render_response_content_status_code_range(
def test_render_response_status_code_range(
testrenderer, oas_fragment, status_range, status_code, status_text
):
"""Path response's example is rendered with proper status range."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand Down Expand Up @@ -578,13 +576,13 @@ def test_render_response_content_status_code_range(
pytest.param("422", "Unprocessable Entity", id="422"),
],
)
def test_render_response_content_status_code_int(
def test_render_response_status_code_int(
testrenderer, oas_fragment, status_code, status_text
):
"""Path response's example is rendered with proper status code."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand All @@ -609,11 +607,11 @@ def test_render_response_content_status_code_int(
)


def test_render_response_content_status_code_default(testrenderer, oas_fragment):
def test_render_response_status_code_default(testrenderer, oas_fragment):
"""Path response's example is rendered when default is passed."""

markup = textify(
testrenderer.render_response_content(
testrenderer.render_response_example(
oas_fragment(
"""
text/csv:
Expand Down

0 comments on commit 4e08f1a

Please sign in to comment.