1
1
from django .http import response
2
2
from django .test import TestCase
3
- import json
4
3
from graphene_django .utils .testing import GraphQLTestCase
4
+ import json
5
5
from student .models import Student
6
6
from mixer .backend .django import mixer
7
7
8
- class testCasesForStudents (GraphQLTestCase ):
8
+
9
+ class StudentTestCases (GraphQLTestCase ):
9
10
GRAPHQL_URL = 'http://localhost/graphql'
11
+
10
12
def setUp (self ):
11
- super ().setUp ()
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 )
13
+ super ().setUp ()
14
+ self .student1 = mixer .blend (Student , name = 'student1' , roll_no = '1' , parentId = 'root' ,year = 2019 )
15
+ self .student2 = mixer .blend (Student , name = 'student2' , roll_no = '2' , parentId = '1' , year = 2020 )
16
+ self .student3 = mixer .blend (Student , name = 'student3' , roll_no = '3' , parentId = '1' , year = 2020 )
17
+ self .student4 = mixer .blend (Student , name = 'student4' , roll_no = '4' , parentId = '1' , year = 2020 )
18
+ self .student5 = mixer .blend (Student , name = 'student5' , roll_no = '5' , parentId = '2' )
19
+ self .student6 = mixer .blend (Student , name = 'student6' , roll_no = '6' , parentId = '5' )
20
+ self .student7 = mixer .blend (Student , name = 'student7' , roll_no = '7' , parentId = '6' )
21
+ self .student8 = mixer .blend (Student , name = 'student8' , roll_no = '8' , parentId = '7' )
22
+ self .student9 = mixer .blend (Student , name = 'student9' , roll_no = '9' , parentId = '8' )
23
+
24
+ def test_children_query (self ):
25
+ response = self .query ('''
26
+ query {
27
+ children(parentId: "1"){
28
+ rollNo
29
+ name
30
+ }
31
+ }
32
+ ''' )
33
+
34
+ content = json .loads (response .content )
35
+ self .assertResponseNoErrors (response )
36
+ self .assertDictEqual (content ['data' ]['children' ][0 ], {'rollNo' : '2' , 'name' : 'student2' })
37
+ self .assertDictEqual (content ['data' ]['children' ][1 ], {'rollNo' : '3' , 'name' : 'student3' })
38
+ self .assertDictEqual (content ['data' ]['children' ][2 ], {'rollNo' : '4' , 'name' : 'student4' })
39
+
16
40
def test_student_query (self ):
17
41
response = self .query ('''
18
42
query {
@@ -22,10 +46,11 @@ def test_student_query(self):
22
46
}
23
47
}
24
48
''' )
25
- content = json .loads (response .content )
49
+ content = json .loads (response .content )
26
50
self .assertResponseNoErrors (response )
27
51
self .assertDictEqual (content ['data' ]['students' ][0 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
28
52
self .assertDictEqual (content ['data' ]['students' ][1 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })
53
+
29
54
def test_student_sibling (self ):
30
55
response = self .query ('''
31
56
query {
@@ -44,11 +69,11 @@ def test_student_batch(self):
44
69
response = self .query ('''
45
70
query {
46
71
studentBatch(roll: "2") {
47
- id
48
- name
49
- }
72
+ id
73
+ name
50
74
}
51
- ''' )
75
+ }
76
+ ''' )
52
77
content = json .loads (response .content )
53
78
self .assertResponseNoErrors (response )
54
79
self .assertDictEqual (content ['data' ]['studentBatch' ][0 ][0 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })
@@ -57,5 +82,23 @@ def test_student_batch(self):
57
82
self .assertDictEqual (content ['data' ]['studentBatch' ][1 ][1 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
58
83
self .assertDictEqual (content ['data' ]['studentBatch' ][2 ][0 ], {'id' : str (self .student4 .id ), 'name' : self .student4 .name })
59
84
self .assertDictEqual (content ['data' ]['studentBatch' ][1 ][1 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
60
-
61
-
85
+
86
+ def test_student_path (self ):
87
+ response = self .query ('''
88
+ query {
89
+ studentPath(roll: "9") {
90
+ id
91
+ name
92
+ }
93
+ }
94
+ ''' )
95
+ content = json .loads (response .content )
96
+ self .assertResponseNoErrors (response )
97
+ self .assertDictEqual (content ['data' ]['studentPath' ][6 ], {'id' : str (self .student1 .id ), 'name' : self .student1 .name })
98
+ self .assertDictEqual (content ['data' ]['studentPath' ][5 ], {'id' : str (self .student2 .id ), 'name' : self .student2 .name })
99
+ self .assertDictEqual (content ['data' ]['studentPath' ][4 ], {'id' : str (self .student5 .id ), 'name' : self .student5 .name })
100
+ self .assertDictEqual (content ['data' ]['studentPath' ][3 ], {'id' : str (self .student6 .id ), 'name' : self .student6 .name })
101
+ self .assertDictEqual (content ['data' ]['studentPath' ][2 ], {'id' : str (self .student7 .id ), 'name' : self .student7 .name })
102
+ self .assertDictEqual (content ['data' ]['studentPath' ][1 ], {'id' : str (self .student8 .id ), 'name' : self .student8 .name })
103
+ self .assertDictEqual (content ['data' ]['studentPath' ][0 ], {'id' : str (self .student9 .id ), 'name' : self .student9 .name })
104
+
0 commit comments