-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert
ResourceRelatedField
test to pytest styled tests (#887)
- Loading branch information
Showing
6 changed files
with
229 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
"example", | ||
"debug_toolbar", | ||
"django_filters", | ||
"tests", | ||
] | ||
|
||
TEMPLATES = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from rest_framework_json_api.relations import ResourceRelatedField | ||
from rest_framework_json_api.serializers import ModelSerializer | ||
from tests.models import ( | ||
BasicModel, | ||
ForeignKeySource, | ||
ForeignKeyTarget, | ||
ManyToManySource, | ||
ManyToManyTarget, | ||
) | ||
|
||
|
||
class BasicModelSerializer(ModelSerializer): | ||
class Meta: | ||
fields = ("text",) | ||
model = BasicModel | ||
|
||
|
||
class ForeignKeySourceSerializer(ModelSerializer): | ||
target = ResourceRelatedField(queryset=ForeignKeyTarget.objects) | ||
|
||
class Meta: | ||
model = ForeignKeySource | ||
fields = ("target",) | ||
|
||
|
||
class ManyToManySourceSerializer(ModelSerializer): | ||
targets = ResourceRelatedField(many=True, queryset=ManyToManyTarget.objects) | ||
|
||
class Meta: | ||
model = ManyToManySource | ||
fields = ("targets",) | ||
|
||
|
||
class ManyToManyTargetSerializer(ModelSerializer): | ||
class Meta: | ||
model = ManyToManyTarget | ||
|
||
|
||
class ManyToManySourceReadOnlySerializer(ModelSerializer): | ||
targets = ResourceRelatedField(many=True, read_only=True) | ||
|
||
class Meta: | ||
model = ManyToManySource | ||
fields = ("targets",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.