mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 02:54:06 +03:00
added ModelSerializer tests
This commit is contained in:
parent
3d30038795
commit
c72e7e55eb
|
@ -8,6 +8,7 @@ SECRET_KEY = 1
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'graphene_django',
|
'graphene_django',
|
||||||
|
'graphene_django.rest_framework',
|
||||||
'graphene_django.tests',
|
'graphene_django.tests',
|
||||||
'starwars',
|
'starwars',
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
from django.db import models
|
import datetime
|
||||||
|
|
||||||
from graphene import Field
|
from graphene import Field
|
||||||
from graphene.types.inputobjecttype import InputObjectType
|
from graphene.types.inputobjecttype import InputObjectType
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
from py.test import mark
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from ...types import DjangoObjectType
|
from ...types import DjangoObjectType
|
||||||
|
from ..models import MyFakeModel
|
||||||
from ..mutation import SerializerMutation
|
from ..mutation import SerializerMutation
|
||||||
|
|
||||||
|
|
||||||
class MyFakeModel(models.Model):
|
|
||||||
cool_name = models.CharField(max_length=50)
|
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
|
|
||||||
|
|
||||||
class MyModelSerializer(serializers.ModelSerializer):
|
class MyModelSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MyFakeModel
|
model = MyFakeModel
|
||||||
|
@ -90,6 +88,19 @@ def test_mutate_and_get_payload_success():
|
||||||
assert result.errors is None
|
assert result.errors is None
|
||||||
|
|
||||||
|
|
||||||
|
@mark.django_db
|
||||||
|
def test_model_mutate_and_get_payload_success():
|
||||||
|
class MyMutation(SerializerMutation):
|
||||||
|
class Meta:
|
||||||
|
serializer_class = MyModelSerializer
|
||||||
|
|
||||||
|
result = MyMutation.mutate_and_get_payload(None, None, **{
|
||||||
|
'cool_name': 'Narf',
|
||||||
|
})
|
||||||
|
assert result.errors is None
|
||||||
|
assert result.cool_name == 'Narf'
|
||||||
|
assert isinstance(result.created, datetime.datetime)
|
||||||
|
|
||||||
def test_mutate_and_get_payload_error():
|
def test_mutate_and_get_payload_error():
|
||||||
|
|
||||||
class MyMutation(SerializerMutation):
|
class MyMutation(SerializerMutation):
|
||||||
|
@ -99,3 +110,13 @@ def test_mutate_and_get_payload_error():
|
||||||
# missing required fields
|
# missing required fields
|
||||||
result = MyMutation.mutate_and_get_payload(None, None, **{})
|
result = MyMutation.mutate_and_get_payload(None, None, **{})
|
||||||
assert len(result.errors) > 0
|
assert len(result.errors) > 0
|
||||||
|
|
||||||
|
def test_model_mutate_and_get_payload_error():
|
||||||
|
|
||||||
|
class MyMutation(SerializerMutation):
|
||||||
|
class Meta:
|
||||||
|
serializer_class = MyModelSerializer
|
||||||
|
|
||||||
|
# missing required fields
|
||||||
|
result = MyMutation.mutate_and_get_payload(None, None, **{})
|
||||||
|
assert len(result.errors) > 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user