2015-07-16 15:40:41 +03:00
|
|
|
from django.conf.urls import url
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.utils import override_settings
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
|
|
|
from rest_framework.generics import ListCreateAPIView
|
|
|
|
from rest_framework.renderers import BrowsableAPIRenderer
|
|
|
|
|
|
|
|
|
|
|
|
class NestedSerializer(serializers.Serializer):
|
|
|
|
one = serializers.IntegerField(max_value=10)
|
|
|
|
two = serializers.IntegerField(max_value=10)
|
|
|
|
|
|
|
|
|
2016-04-11 16:13:11 +03:00
|
|
|
class NestedSerializerTestSerializer(serializers.Serializer):
|
2015-07-16 15:40:41 +03:00
|
|
|
nested = NestedSerializer()
|
|
|
|
|
|
|
|
|
|
|
|
class NestedSerializersView(ListCreateAPIView):
|
|
|
|
renderer_classes = (BrowsableAPIRenderer, )
|
2016-04-11 16:13:11 +03:00
|
|
|
serializer_class = NestedSerializerTestSerializer
|
2015-07-16 15:40:41 +03:00
|
|
|
queryset = [{'nested': {'one': 1, 'two': 2}}]
|
|
|
|
|
|
|
|
|
|
|
|
urlpatterns = [
|
|
|
|
url(r'^api/$', NestedSerializersView.as_view(), name='api'),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class DropdownWithAuthTests(TestCase):
|
|
|
|
"""Tests correct dropdown behaviour with Auth views enabled."""
|
|
|
|
|
|
|
|
@override_settings(ROOT_URLCONF='tests.browsable_api.test_browsable_nested_api')
|
|
|
|
def test_login(self):
|
|
|
|
response = self.client.get('/api/')
|
2016-12-01 19:17:36 +03:00
|
|
|
assert 200 == response.status_code
|
2019-05-01 08:49:17 +03:00
|
|
|
content = response.content.decode()
|
2016-12-01 19:17:36 +03:00
|
|
|
assert 'form action="/api/"' in content
|
|
|
|
assert 'input name="nested.one"' in content
|
|
|
|
assert 'input name="nested.two"' in content
|