mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
add tests for #4965
This commit is contained in:
parent
871ce34983
commit
7b0689a67f
0
tests/interactive_doc/__init__.py
Normal file
0
tests/interactive_doc/__init__.py
Normal file
18
tests/interactive_doc/data.py
Normal file
18
tests/interactive_doc/data.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.db import models
|
||||
from rest_framework import serializers, viewsets
|
||||
|
||||
|
||||
class DummyModel(models.Model):
|
||||
pass
|
||||
|
||||
|
||||
class DummySerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = DummyModel
|
||||
fields = ('id', )
|
||||
|
||||
|
||||
class DummyViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = DummySerializer
|
||||
queryset = DummyModel.objects.all()
|
38
tests/interactive_doc/test_recursive_url.py
Normal file
38
tests/interactive_doc/test_recursive_url.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
from django.test import TestCase, override_settings
|
||||
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='tests.interactive_doc.urls')
|
||||
class TestRecursiveUrlViewSets(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
client = APIClient()
|
||||
response = client.get('/docs/')
|
||||
self.content = response.content.decode('utf-8')
|
||||
|
||||
def test_menu(self):
|
||||
self.assertTrue(
|
||||
re.search('a href="#.*not_dummies\-list">', self.content),
|
||||
'unable to find menu item for not_dummies'
|
||||
)
|
||||
for model_type in ['aaaa', 'bbbb']:
|
||||
self.assertTrue(
|
||||
re.search('a href="#.*{}s\-list">'.format(model_type), self.content),
|
||||
'unable to find menu item for dummy/{}'.format(model_type)
|
||||
)
|
||||
|
||||
def test_documentation(self):
|
||||
self.assertTrue(
|
||||
re.search('h2.*>not_dummies <a', self.content),
|
||||
'unable to find documentation section for not_dummies'
|
||||
)
|
||||
for model_type in ['aaaa', 'bbbb']:
|
||||
self.assertTrue(
|
||||
re.search('h3.*>{}s <a'.format(model_type), self.content),
|
||||
'unable to find documentation section for dummy/{}'.format(model_type)
|
||||
)
|
18
tests/interactive_doc/urls.py
Normal file
18
tests/interactive_doc/urls.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.conf.urls import include, url
|
||||
|
||||
from rest_framework.documentation import include_docs_urls
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from .data import DummyViewSet
|
||||
|
||||
|
||||
router = DefaultRouter()
|
||||
|
||||
router.register(r'dummy/aaaas', DummyViewSet)
|
||||
router.register(r'dummy/bbbbs', DummyViewSet)
|
||||
router.register(r'not_dummies', DummyViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'', include(router.urls)),
|
||||
url(r'^docs/', include_docs_urls())
|
||||
]
|
Loading…
Reference in New Issue
Block a user