1- from django .db import models
1+ import datetime
2+
23from graphene import Field
34from graphene .types .inputobjecttype import InputObjectType
45from py .test import raises
6+ from py .test import mark
57from rest_framework import serializers
68
79from ...types import DjangoObjectType
10+ from ..models import MyFakeModel
811from ..mutation import SerializerMutation
912
1013
11- class MyFakeModel (models .Model ):
12- cool_name = models .CharField (max_length = 50 )
13- created = models .DateTimeField (auto_now_add = True )
14-
15-
1614class MyModelSerializer (serializers .ModelSerializer ):
1715 class Meta :
1816 model = MyFakeModel
@@ -90,6 +88,19 @@ class Meta:
9088 assert result .errors is None
9189
9290
91+ @mark .django_db
92+ def test_model_mutate_and_get_payload_success ():
93+ class MyMutation (SerializerMutation ):
94+ class Meta :
95+ serializer_class = MyModelSerializer
96+
97+ result = MyMutation .mutate_and_get_payload (None , None , ** {
98+ 'cool_name' : 'Narf' ,
99+ })
100+ assert result .errors is None
101+ assert result .cool_name == 'Narf'
102+ assert isinstance (result .created , datetime .datetime )
103+
93104def test_mutate_and_get_payload_error ():
94105
95106 class MyMutation (SerializerMutation ):
@@ -98,4 +109,14 @@ class Meta:
98109
99110 # missing required fields
100111 result = MyMutation .mutate_and_get_payload (None , None , ** {})
101- assert len (result .errors ) > 0
112+ assert len (result .errors ) > 0
113+
114+ def test_model_mutate_and_get_payload_error ():
115+
116+ class MyMutation (SerializerMutation ):
117+ class Meta :
118+ serializer_class = MyModelSerializer
119+
120+ # missing required fields
121+ result = MyMutation .mutate_and_get_payload (None , None , ** {})
122+ assert len (result .errors ) > 0
0 commit comments