From f54a220d8f3c8649b84188c7e2a6dc2ef3be6f4c Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Thu, 31 Jan 2019 11:36:40 +0100 Subject: [PATCH] Corrected coreapi CLI code example generation. (#6428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove “> “ when rendering template. Closes #6333. --- .../templates/rest_framework/docs/langs/shell.html | 2 +- tests/test_renderers.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rest_framework/templates/rest_framework/docs/langs/shell.html b/rest_framework/templates/rest_framework/docs/langs/shell.html index 24137e4ae..e5f2a0322 100644 --- a/rest_framework/templates/rest_framework/docs/langs/shell.html +++ b/rest_framework/templates/rest_framework/docs/langs/shell.html @@ -3,4 +3,4 @@ $ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %} # Interact with the API endpoint -$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %} +$ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key|cut:"> " }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %} diff --git a/tests/test_renderers.py b/tests/test_renderers.py index a68ece734..8518a3f7c 100644 --- a/tests/test_renderers.py +++ b/tests/test_renderers.py @@ -9,6 +9,7 @@ from django.conf.urls import include, url from django.core.cache import cache from django.db import models from django.http.request import HttpRequest +from django.template import loader from django.test import TestCase, override_settings from django.utils import six from django.utils.safestring import SafeText @@ -827,6 +828,16 @@ class TestDocumentationRenderer(TestCase): html = renderer.render(document, accepted_media_type="text/html", renderer_context={"request": request}) assert '

Data Endpoint API

' in html + def test_shell_code_example_rendering(self): + template = loader.get_template('rest_framework/docs/langs/shell.html') + context = { + 'document': coreapi.Document(url='https://api.example.org/'), + 'link_key': 'testcases > list', + 'link': coreapi.Link(url='/data/', action='get', fields=[]), + } + html = template.render(context) + assert 'testcases list' in html + @pytest.mark.skipif(not coreapi, reason='coreapi is not installed') class TestSchemaJSRenderer(TestCase):