Hypothesis DRF
Project description
[Hypothesis](https://github.com/HypothesisWorks/hypothesis-python) strategy for
[Django REST framework](http://www.django-rest-framework.org/) serializers.
Generate data that is valid according to a DRF serializer
### Known issues
* `URLField` can be slow when generating the first example
* Not all fields are supported, known non-working:
- FileField
- FilePathField
- ImageField
- ModelField
* Only tested with python3.6
### Example
```bash
pip install hypothesis-drf
```
```python
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)
from_serializer(ExampleSerializer).example()
# {'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:
```python
from rest_framework import fields
from hypothesis import strategies as st
class MyField(fields.Field):
hypothesis_strategy = st.booleans()
# ...
```
[Django REST framework](http://www.django-rest-framework.org/) serializers.
Generate data that is valid according to a DRF serializer
### Known issues
* `URLField` can be slow when generating the first example
* Not all fields are supported, known non-working:
- FileField
- FilePathField
- ImageField
- ModelField
* Only tested with python3.6
### Example
```bash
pip install hypothesis-drf
```
```python
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)
from_serializer(ExampleSerializer).example()
# {'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:
```python
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.4.tar.gz
(6.6 kB
view details)
Built Distribution
File details
Details for the file hypothesis-drf-0.0.4.tar.gz
.
File metadata
- Download URL: hypothesis-drf-0.0.4.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4d79ea8dad09d1e7cacea890c67d2e4e7346494c6c2d64219692c367d1b778af
|
|
MD5 |
0b25ac879c1529ecf96877bf053161bd
|
|
BLAKE2b-256 |
ccc9985fcbd3ca22e69c3ffea47255df856ae1879e2fb7e195c10a68275d5e9f
|
File details
Details for the file hypothesis_drf-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: hypothesis_drf-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
5122439393049355b4da900de5167cc381fae6cc9d75600eff3c1f98bbb6a3fd
|
|
MD5 |
82900c5c07a45e8d44a4ec660d5979e3
|
|
BLAKE2b-256 |
f3381a67d0c44596491ff83698f168ee9c2a61c8298a03ffed846bb29a23c1ce
|