1
1
from django .test import TestCase
2
- import json
3
2
from graphene_django .utils .testing import GraphQLTestCase
3
+ import json
4
4
from student .models import Student
5
5
from mixer .backend .django import mixer
6
6
7
- class testCasesForStudents (GraphQLTestCase ):
7
+
8
+ class StudentTestCases (GraphQLTestCase ):
8
9
GRAPHQL_URL = 'http://localhost/graphql'
10
+
9
11
def setUp (self ):
10
- 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
+ super ().setUp ()
13
+ self .student1 = mixer .blend (Student , name = 'student1' , roll_no = '1' , parentId = 'root' )
14
+ self .student2 = mixer .blend (Student , name = 'student2' , roll_no = '2' , parentId = '1' )
15
+ self .student3 = mixer .blend (Student , name = 'student3' , roll_no = '3' , parentId = '1' )
16
+ self .student4 = mixer .blend (Student , name = 'student4' , roll_no = '4' , parentId = '1' )
17
+
18
+
19
+ def test_children_query (self ):
20
+ response = self .query ('''
21
+ query {
22
+ children(parentId: "1"){
23
+ rollNo
24
+ name
25
+ }
26
+ }
27
+ ''' )
28
+
29
+ content = json .loads (response .content )
30
+ self .assertResponseNoErrors (response )
31
+ self .assertDictEqual (content ['data' ]['children' ][0 ], {'rollNo' : '2' , 'name' : 'student2' })
32
+ self .assertDictEqual (content ['data' ]['children' ][1 ], {'rollNo' : '3' , 'name' : 'student3' })
33
+ self .assertDictEqual (content ['data' ]['children' ][2 ], {'rollNo' : '4' , 'name' : 'student4' })
34
+
15
35
def test_student_query (self ):
16
36
response = self .query ('''
17
37
query {
@@ -21,10 +41,11 @@ def test_student_query(self):
21
41
}
22
42
}
23
43
''' )
24
- content = json .loads (response .content )
44
+ content = json .loads (response .content )
25
45
self .assertResponseNoErrors (response )
26
46
self .assertDictEqual (content ['data' ]['students' ][0 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
27
- self .assertDictEqual (content ['data' ]['students' ][1 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })
47
+ self .assertDictEqual (content ['data' ]['students' ][1 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })\
48
+
28
49
def test_student_sibling (self ):
29
50
response = self .query ('''
30
51
query {
@@ -37,4 +58,4 @@ def test_student_sibling(self):
37
58
content = json .loads (response .content )
38
59
self .assertResponseNoErrors (response )
39
60
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 })
61
+ self .assertDictEqual (content ['data' ]['studentSibling' ][1 ], {'id' : str (self .student4 .id ), 'name' : self .student4 .name })
0 commit comments