forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_groups_resolver.py
More file actions
215 lines (191 loc) · 6.06 KB
/
Copy pathtest_groups_resolver.py
File metadata and controls
215 lines (191 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import sys
import os
from os.path import dirname, join, expanduser, normpath, realpath
import pytest
from graphene.test import Client
from unittest import TestCase
from manage import seed, remove_seed
seed()
from app import app
from db import db
from models import Sectors, Groups
from queries import schema
remove_seed()
# This is the only way I could get imports to work for unit testing.
PACKAGE_PARENT = '..'
SCRIPT_DIR = dirname(realpath(join(os.getcwd(), expanduser(__file__))))
sys.path.append(normpath(join(SCRIPT_DIR, PACKAGE_PARENT)))
@pytest.fixture(scope='class')
def group_test_db_init():
db.init_app(app)
with app.app_context():
sector = Sectors(
id=1,
zone="GC",
sector="GC_A",
description="Arts"
)
db.session.add(sector)
sector = Sectors(
id=2,
zone="GC",
sector="GC_BF",
description="Banking and Finance"
)
db.session.add(sector)
sector = Sectors(
id=25,
zone="TEST",
sector="TEST_DEV",
description="Development test cases"
)
db.session.add(sector)
db.session.commit()
group = Groups(
id=1,
s_group='GC_A',
description='Arts',
sector_id=1
)
db.session.add(group)
group = Groups(
id=2,
s_group='GC_BF',
description='Banking and Finance',
sector_id=2
)
db.session.add(group)
yield
with app.app_context():
Groups.query.delete()
Sectors.query.delete()
db.session.commit()
@pytest.mark.usefixtures('group_test_db_init')
class TestGroupResolver(TestCase):
def test_get_group_resolvers_by_id(self):
"""Test get_group_by_id resolver"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupById(id:1) {
sGroup,
description
}
}"""
result_refr = {
"data": {
"getGroupById": [
{
"sGroup": "GC_A",
"description": "Arts"
}
]
}
}
result_eval = client.execute(query)
self.assertDictEqual(result_refr, result_eval)
def test_get_group_resolvers_by_group(self):
""""Test get_group_by_group resolver"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupByGroup(group: GC_A){
description
sectorId
}
}"""
result_refr = {
"data": {
"getGroupByGroup": [
{
"description": "Arts",
"sectorId": 1
}
]
}
}
result_eval = client.execute(query)
self.assertDictEqual(result_refr, result_eval)
def test_get_group_resolvers_by_sector(self):
"""Test get_group_by_sector_id resolver"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupBySector(sector: GC_A){
description
groupSector{
id
zone
description
}
}
}"""
result_refr = {
"data": {
"getGroupBySector": [
{
"description": "Arts",
"groupSector": {
"id": "U2VjdG9yczox",
"zone": "GC",
"description": "Arts"
}
}
]
}
}
result_eval = client.execute(query)
self.assertDictEqual(result_refr, result_eval)
def test_group_resolver_by_id_invalid(self):
"""Test get_group_by_id invalid ID error handling"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupById(id: 9999){
id
description
sectorId
}
}"""
executed = client.execute(query)
assert executed['errors']
assert executed['errors'][0]
assert executed['errors'][0]['message'] == "Error, Invalid ID"
def test_group_resolver_by_group_invalid(self):
"""Test get_group_by_group invalid sector error handling"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupByGroup(group: fds){
id
description
sectorId
}
}"""
executed = client.execute(query)
assert executed['errors']
assert executed['errors'][0]
assert executed['errors'][0][
'message'] == f'Argument "group" has invalid value fds.\nExpected type "GroupEnums", found fds.'
def test_group_resolver_by_sector_invalid(self):
"""Test get_group_by_sector invalid Zone error handling"""
with app.app_context():
client = Client(schema)
query = """
{
getGroupBySector(sector: dsa){
id
description
sectorId
}
}"""
executed = client.execute(query)
assert executed['errors']
assert executed['errors'][0]
assert executed['errors'][0][
'message'] == f'Argument "sector" has invalid value dsa.\nExpected type "SectorEnums", found dsa.'