1
- from django .db import models
1
+ import datetime
2
+
2
3
from graphene import Field
3
4
from graphene .types .inputobjecttype import InputObjectType
4
5
from py .test import raises
6
+ from py .test import mark
5
7
from rest_framework import serializers
6
8
7
9
from ...types import DjangoObjectType
10
+ from ..models import MyFakeModel
8
11
from ..mutation import SerializerMutation
9
12
10
13
11
- class MyFakeModel (models .Model ):
12
- cool_name = models .CharField (max_length = 50 )
13
-
14
-
15
14
class MyModelSerializer (serializers .ModelSerializer ):
16
15
class Meta :
17
16
model = MyFakeModel
@@ -71,6 +70,7 @@ class Meta:
71
70
model_input_type = model_input ._type .of_type
72
71
assert issubclass (model_input_type , InputObjectType )
73
72
assert 'cool_name' in model_input_type ._meta .fields
73
+ assert 'created' in model_input_type ._meta .fields
74
74
75
75
76
76
def test_mutate_and_get_payload_success ():
@@ -88,6 +88,19 @@ class Meta:
88
88
assert result .errors is None
89
89
90
90
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
+
91
104
def test_mutate_and_get_payload_error ():
92
105
93
106
class MyMutation (SerializerMutation ):
@@ -96,4 +109,14 @@ class Meta:
96
109
97
110
# missing required fields
98
111
result = MyMutation .mutate_and_get_payload (None , None , ** {})
99
- 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