Skip to content

Commit f54a220

Browse files
Corrected coreapi CLI code example generation. (#6428)
Remove “> “ when rendering template. Closes #6333.
1 parent 87ade87 commit f54a220

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

rest_framework/templates/rest_framework/docs/langs/shell.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
44

55
# Interact with the API endpoint
6-
$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>
6+
$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key|cut:"> " }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</code></pre>

tests/test_renderers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.core.cache import cache
1010
from django.db import models
1111
from django.http.request import HttpRequest
12+
from django.template import loader
1213
from django.test import TestCase, override_settings
1314
from django.utils import six
1415
from django.utils.safestring import SafeText
@@ -827,6 +828,16 @@ def test_document_with_link_named_data(self):
827828
html = renderer.render(document, accepted_media_type="text/html", renderer_context={"request": request})
828829
assert '<h1>Data Endpoint API</h1>' in html
829830

831+
def test_shell_code_example_rendering(self):
832+
template = loader.get_template('rest_framework/docs/langs/shell.html')
833+
context = {
834+
'document': coreapi.Document(url='https://api.example.org/'),
835+
'link_key': 'testcases > list',
836+
'link': coreapi.Link(url='/data/', action='get', fields=[]),
837+
}
838+
html = template.render(context)
839+
assert 'testcases list' in html
840+
830841

831842
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
832843
class TestSchemaJSRenderer(TestCase):

0 commit comments

Comments
 (0)