Skip to main content

Hypothesis DRF

Project description

[Hypothesis]( strategy for
[Django REST framework](

### Known issues

* `URLField` can be slow when generating the first example
* Not all fields are supported, known non-working:
- FileField
- FilePathField
- ImageField
- ModelField
- JSONField(allow_null=False)

### Example

import json
from hypothesis_drf import from_serializer, from_field
from rest_framework import serializers

class ExampleSerializer(serializers.Serializer):
name = serializers.CharField(min_length=3, max_length=8)
amount = serializers.IntegerField(min_value=200, max_value=500)

# {'amount': 391, 'name': '\U00053a6b&\U00030fee$.'}

from_field(serializers.FloatField(min_value=-10, max_value=22)
# -8.499125311228873


### Custom fields

Provide `hypothesis_strategy` on the field:

from rest_framework import fields
from hypothesis import strategies as st

class MyField(fields.Field):
hypothesis_strategy = st.booleans()

# ...

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypothesis-drf-0.0.1.tar.gz (6.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page