1
+ from django .http import response
1
2
from django .test import TestCase
2
3
import json
3
4
from graphene_django .utils .testing import GraphQLTestCase
@@ -8,10 +9,10 @@ class testCasesForStudents(GraphQLTestCase):
8
9
GRAPHQL_URL = 'http://localhost/graphql'
9
10
def setUp (self ):
10
11
super ().setUp ()
11
- self .student1 = mixer .blend (Student , name = 'student1' , roll_no = '1' , parentId = 'root' )
12
- self .student2 = mixer .blend (Student , name = 'student2' , roll_no = '2' , parentId = '1' )
13
- self .student3 = mixer .blend (Student , name = 'student3' , roll_no = '3' , parentId = '1' )
14
- self .student4 = mixer .blend (Student , name = 'student4' , roll_no = '4' , parentId = '1' )
12
+ self .student1 = mixer .blend (Student , name = 'student1' , roll_no = '1' , parentId = 'root' , year = 2019 )
13
+ self .student2 = mixer .blend (Student , name = 'student2' , roll_no = '2' , parentId = '1' , year = 2020 )
14
+ self .student3 = mixer .blend (Student , name = 'student3' , roll_no = '3' , parentId = '1' , year = 2020 )
15
+ self .student4 = mixer .blend (Student , name = 'student4' , roll_no = '4' , parentId = '1' , year = 2020 )
15
16
def test_student_query (self ):
16
17
response = self .query ('''
17
18
query {
@@ -37,4 +38,24 @@ def test_student_sibling(self):
37
38
content = json .loads (response .content )
38
39
self .assertResponseNoErrors (response )
39
40
self .assertDictEqual (content ['data' ]['studentSibling' ][0 ], {'id' : str (self .student3 .id ), 'name' : self .student3 .name })
40
- self .assertDictEqual (content ['data' ]['studentSibling' ][1 ], {'id' : str (self .student4 .id ), 'name' : self .student4 .name })
41
+ self .assertDictEqual (content ['data' ]['studentSibling' ][1 ], {'id' : str (self .student4 .id ), 'name' : self .student4 .name })
42
+
43
+ def test_student_batch (self ):
44
+ response = self .query ('''
45
+ query {
46
+ studentBatch(roll: "2") {
47
+ id
48
+ name
49
+ }
50
+ }
51
+ ''' )
52
+ content = json .loads (response .content )
53
+ self .assertResponseNoErrors (response )
54
+ self .assertDictEqual (content ['data' ]['studentBatch' ][0 ][0 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })
55
+ self .assertDictEqual (content ['data' ]['studentBatch' ][0 ][1 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
56
+ self .assertDictEqual (content ['data' ]['studentBatch' ][1 ][0 ], {'id' : str (self .student3 .id ), 'name' : self .student3 .name })
57
+ self .assertDictEqual (content ['data' ]['studentBatch' ][1 ][1 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
58
+ self .assertDictEqual (content ['data' ]['studentBatch' ][2 ][0 ], {'id' : str (self .student4 .id ), 'name' : self .student4 .name })
59
+ self .assertDictEqual (content ['data' ]['studentBatch' ][1 ][1 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
60
+
61
+
0 commit comments