mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 04:02:35 +03:00
added testcase for rendering yaml with minvalidator for duration field (timedelta)
This commit is contained in:
parent
95aad32e06
commit
c5613a8ed4
|
@ -1174,6 +1174,19 @@ class TestGenerator(TestCase):
|
|||
assert b"openapi: " in ret
|
||||
assert b"default: '0.0'" in ret
|
||||
|
||||
def test_schema_rendering_timedelta_to_yaml_with_validator(self):
|
||||
|
||||
patterns = [
|
||||
path('example/', views.ExampleValidatedAPIView.as_view()),
|
||||
]
|
||||
generator = SchemaGenerator(patterns=patterns)
|
||||
|
||||
request = create_request('/')
|
||||
schema = generator.get_schema(request=request)
|
||||
ret = OpenAPIRenderer().render(schema)
|
||||
assert b"openapi: " in ret
|
||||
assert b"duration:\n type: string\n minimum: \'10.0\'\n" in ret
|
||||
|
||||
def test_schema_with_no_paths(self):
|
||||
patterns = []
|
||||
generator = SchemaGenerator(patterns=patterns)
|
||||
|
|
|
@ -134,6 +134,11 @@ class ExampleValidatedSerializer(serializers.Serializer):
|
|||
ip4 = serializers.IPAddressField(protocol='ipv4')
|
||||
ip6 = serializers.IPAddressField(protocol='ipv6')
|
||||
ip = serializers.IPAddressField()
|
||||
duration = serializers.DurationField(
|
||||
validators=(
|
||||
MinValueValidator(timedelta(seconds=10)),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ExampleValidatedAPIView(generics.GenericAPIView):
|
||||
|
|
Loading…
Reference in New Issue
Block a user