fixed tests

This commit is contained in:
kuter 2019-02-11 22:18:26 +01:00
parent 6971c169d4
commit 1cb0a0ccd5

View File

@ -1,11 +1,15 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import django
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
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from six import StringIO from six import StringIO
from rest_framework.compat import coreapi
from rest_framework.utils import json
from rest_framework.views import APIView from rest_framework.views import APIView
@ -20,12 +24,14 @@ urlpatterns = [
@override_settings(ROOT_URLCONF='tests.test_generateschema') @override_settings(ROOT_URLCONF='tests.test_generateschema')
@pytest.mark.skipif(not coreapi, reason='coreapi is not installed')
class GenerateSchemaTests(TestCase): class GenerateSchemaTests(TestCase):
"""Tests for management command generateschema.""" """Tests for management command generateschema."""
def setUp(self): # noqa def setUp(self): # noqa
self.out = StringIO() 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_should_render_default_schema_with_custom_title_url_and_description(self): # noqa
expected_out = """info: expected_out = """info:
description: Sample description description: Sample description
@ -44,34 +50,36 @@ servers:
'--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(expected_out, self.out.getvalue())
def test_should_render_openapi_json_schema(self): # noqa def test_should_render_openapi_json_schema(self): # noqa
expected_out = """{ expected_out = {
"openapi": "3.0.0", "openapi": "3.0.0",
"info": { "info": {
"version": "", "version": "",
"title": "", "title": "",
"description": "" "description": ""
}, },
"servers": [ "servers": [
{ {
"url": "" "url": ""
} }
], ],
"paths": { "paths": {
"/": { "/": {
"get": { "get": {
"operationId": "list" "operationId": "list"
}
}
} }
} }
}
}
"""
call_command('generateschema', call_command('generateschema',
'--format=openapi-json', '--format=openapi-json',
stdout=self.out) stdout=self.out)
self.assertIn(expected_out, self.out.getvalue()) out_json = json.loads(self.out.getvalue())
self.assertDictEqual(out_json, expected_out)
def test_should_render_corejson_schema(self): # noqa def test_should_render_corejson_schema(self): # noqa
expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}""" # noqa expected_out = """{"_type":"document","":{"list":{"_type":"link","url":"/","action":"get"}}}""" # noqa