          renderer = DocumentationRenderer()
  
          html = renderer.render(document, accepted_media_type="text/html", renderer_context={"request": request})
          assert '<h1>Data Endpoint API</h1>' in html
 
</s> remove         schema = base64.b64encode(codec.encode(data))
 </s> add         schema = base64.b64encode(codec.encode(data)).decode('ascii') </s> remove     HTMLFormRenderer, JSONRenderer, StaticHTMLRenderer
 </s> add     HTMLFormRenderer, JSONRenderer, SchemaJSRenderer, StaticHTMLRenderer
class TestSchemaJSRenderer(TestCase):

    def test_schemajs_output(self):
        """
        Test output of the SchemaJS renderer as per #5608. Django 2.0 on Py3 prints binary data as b'xyz' in templates,
        and the base64 encoding used by SchemaJSRenderer outputs base64 as binary. Test fix.
        """
        factory = APIRequestFactory()
        request = factory.get('/')

        renderer = SchemaJSRenderer()

        output = renderer.render('data', renderer_context={"request": request})
        assert "'ImRhdGEi'" in output
        assert "'b'ImRhdGEi''" not in output
          renderer = DocumentationRenderer()
  
          html = renderer.render(document, accepted_media_type="text/html", renderer_context={"request": request})
          assert '<h1>Data Endpoint API</h1>' in html
class TestSchemaJSRenderer(TestCase):

    def test_schemajs_output(self):
        """
        Test output of the SchemaJS renderer as per #5608. Django 2.0 on Py3 prints binary data as b'xyz' in templates,
        and the base64 encoding used by SchemaJSRenderer outputs base64 as binary. Test fix.
        """
        factory = APIRequestFactory()
        request = factory.get('/')

        renderer = SchemaJSRenderer()

        output = renderer.render('data', renderer_context={"request": request})
        assert "'ImRhdGEi'" in output
        assert "'b'ImRhdGEi''" not in output
keep keep keep add
 SchemaJSRenderer renders invalid Javascript (#5607)

* SchemaJSRenderer renders invalid Javascript

Under Py3 the base64.b64encode() method returns a binary object, which gets rendered as `b'...'` in schema.js. This results in the output becoming:

    var coreJSON = window.atob('b'eyJf...'');

which is invalid Javascript. Because base64 only uses ASCII characters it is safe to decode('ascii') it. Under Py2 this will result in a unicode object, which is fine. Under Py3 it results in a string, which is also fine. This solves the problem and results in a working schema.js output.

* Add regression test for #5608

* Add regression test for #5608

* Apparently the linter on Travis wants the imports in a different order than on my box... 
tests/test_renderers.py