mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
Edits.
This commit is contained in:
parent
1cb0a0ccd5
commit
095fd7ad8a
|
@ -1,6 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import django
|
||||
import pytest
|
||||
from django.conf.urls import url
|
||||
from django.core.management import call_command
|
||||
|
@ -9,12 +8,12 @@ from django.test.utils import override_settings
|
|||
from six import StringIO
|
||||
|
||||
from rest_framework.compat import coreapi
|
||||
from rest_framework.utils import json
|
||||
from rest_framework.utils import formatting, json
|
||||
from rest_framework.views import APIView
|
||||
|
||||
|
||||
class FooView(APIView): # noqa
|
||||
def get(self, request): # noqa
|
||||
class FooView(APIView):
|
||||
def get(self, request):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -28,32 +27,31 @@ urlpatterns = [
|
|||
class GenerateSchemaTests(TestCase):
|
||||
"""Tests for management command generateschema."""
|
||||
|
||||
def setUp(self): # noqa
|
||||
def setUp(self):
|
||||
self.out = StringIO()
|
||||
|
||||
@pytest.mark.skipif(django.VERSION < (2, 1), reason='Django version < 2.1')
|
||||
def test_should_render_default_schema_with_custom_title_url_and_description(self): # noqa
|
||||
def test_renders_default_schema_with_custom_title_url_and_description(self):
|
||||
expected_out = """info:
|
||||
description: Sample description
|
||||
title: SampleAPI
|
||||
version: ''
|
||||
openapi: 3.0.0
|
||||
paths:
|
||||
openapi: 3.0.0
|
||||
paths:
|
||||
/:
|
||||
get:
|
||||
operationId: list
|
||||
servers:
|
||||
- url: http://api.sample.com/
|
||||
"""
|
||||
servers:
|
||||
- url: http://api.sample.com/
|
||||
"""
|
||||
call_command('generateschema',
|
||||
'--title=SampleAPI',
|
||||
'--url=http://api.sample.com',
|
||||
'--description=Sample description',
|
||||
stdout=self.out)
|
||||
|
||||
self.assertIn(expected_out, self.out.getvalue())
|
||||
self.assertIn(formatting.dedent(expected_out), self.out.getvalue())
|
||||
|
||||
def test_should_render_openapi_json_schema(self): # noqa
|
||||
def test_renders_openapi_json_schema(self):
|
||||
expected_out = {
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
|
@ -81,8 +79,8 @@ servers:
|
|||
|
||||
self.assertDictEqual(out_json, expected_out)
|
||||
|
||||
def test_should_render_corejson_schema(self): # noqa
|
||||
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}""" # noqa
|
||||
def test_renders_corejson_schema(self):
|
||||
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}"""
|
||||
call_command('generateschema',
|
||||
'--format=corejson',
|
||||
stdout=self.out)
|
||||
|
|
Loading…
Reference in New Issue
Block a user