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
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import django
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
@ -9,12 +8,12 @@ from django.test.utils import override_settings
|
||||||
from six import StringIO
|
from six import StringIO
|
||||||
|
|
||||||
from rest_framework.compat import coreapi
|
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
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
|
||||||
class FooView(APIView): # noqa
|
class FooView(APIView):
|
||||||
def get(self, request): # noqa
|
def get(self, request):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,32 +27,31 @@ urlpatterns = [
|
||||||
class GenerateSchemaTests(TestCase):
|
class GenerateSchemaTests(TestCase):
|
||||||
"""Tests for management command generateschema."""
|
"""Tests for management command generateschema."""
|
||||||
|
|
||||||
def setUp(self): # noqa
|
def setUp(self):
|
||||||
self.out = StringIO()
|
self.out = StringIO()
|
||||||
|
|
||||||
@pytest.mark.skipif(django.VERSION < (2, 1), reason='Django version < 2.1')
|
def test_renders_default_schema_with_custom_title_url_and_description(self):
|
||||||
def test_should_render_default_schema_with_custom_title_url_and_description(self): # noqa
|
|
||||||
expected_out = """info:
|
expected_out = """info:
|
||||||
description: Sample description
|
description: Sample description
|
||||||
title: SampleAPI
|
title: SampleAPI
|
||||||
version: ''
|
version: ''
|
||||||
openapi: 3.0.0
|
openapi: 3.0.0
|
||||||
paths:
|
paths:
|
||||||
/:
|
/:
|
||||||
get:
|
get:
|
||||||
operationId: list
|
operationId: list
|
||||||
servers:
|
servers:
|
||||||
- url: http://api.sample.com/
|
- url: http://api.sample.com/
|
||||||
"""
|
"""
|
||||||
call_command('generateschema',
|
call_command('generateschema',
|
||||||
'--title=SampleAPI',
|
'--title=SampleAPI',
|
||||||
'--url=http://api.sample.com',
|
'--url=http://api.sample.com',
|
||||||
'--description=Sample description',
|
'--description=Sample description',
|
||||||
stdout=self.out)
|
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 = {
|
expected_out = {
|
||||||
"openapi": "3.0.0",
|
"openapi": "3.0.0",
|
||||||
"info": {
|
"info": {
|
||||||
|
@ -81,8 +79,8 @@ servers:
|
||||||
|
|
||||||
self.assertDictEqual(out_json, expected_out)
|
self.assertDictEqual(out_json, expected_out)
|
||||||
|
|
||||||
def test_should_render_corejson_schema(self): # noqa
|
def test_renders_corejson_schema(self):
|
||||||
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}""" # noqa
|
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}"""
|
||||||
call_command('generateschema',
|
call_command('generateschema',
|
||||||
'--format=corejson',
|
'--format=corejson',
|
||||||
stdout=self.out)
|
stdout=self.out)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user