mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Regroup code for CoreAPI FK generation tests.
This commit is contained in:
parent
2eab61db90
commit
eefc08a72f
|
@ -465,29 +465,25 @@ class TestSchemaGeneratorWithRestrictedViewSets(TestCase):
|
||||||
assert schema == expected
|
assert schema == expected
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySourceSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = ForeignKeySource
|
|
||||||
fields = ('id', 'name', 'target')
|
|
||||||
|
|
||||||
|
|
||||||
class ForeignKeySourceView(generics.CreateAPIView):
|
|
||||||
queryset = ForeignKeySource.objects.all()
|
|
||||||
serializer_class = ForeignKeySourceSerializer
|
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
@unittest.skipUnless(coreapi, 'coreapi is not installed')
|
||||||
class TestSchemaGeneratorWithForeignKey(TestCase):
|
class TestSchemaGeneratorWithForeignKey(TestCase):
|
||||||
def setUp(self):
|
|
||||||
self.patterns = [
|
|
||||||
url(r'^example/?$', ForeignKeySourceView.as_view()),
|
|
||||||
]
|
|
||||||
|
|
||||||
def test_schema_for_regular_views(self):
|
def test_schema_for_regular_views(self):
|
||||||
"""
|
"""
|
||||||
Ensure that AutoField foreign keys are output as Integer.
|
Ensure that AutoField foreign keys are output as Integer.
|
||||||
"""
|
"""
|
||||||
generator = SchemaGenerator(title='Example API', patterns=self.patterns)
|
class ForeignKeySourceSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = ForeignKeySource
|
||||||
|
fields = ('id', 'name', 'target')
|
||||||
|
|
||||||
|
class ForeignKeySourceView(generics.CreateAPIView):
|
||||||
|
queryset = ForeignKeySource.objects.all()
|
||||||
|
serializer_class = ForeignKeySourceSerializer
|
||||||
|
|
||||||
|
patterns = [
|
||||||
|
url(r'^example/?$', ForeignKeySourceView.as_view()),
|
||||||
|
]
|
||||||
|
generator = SchemaGenerator(title='Example API', patterns=patterns)
|
||||||
schema = generator.get_schema()
|
schema = generator.get_schema()
|
||||||
|
|
||||||
expected = coreapi.Document(
|
expected = coreapi.Document(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user