forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_organization_resolver_values.py
More file actions
177 lines (161 loc) · 4.43 KB
/
Copy pathtest_organization_resolver_values.py
File metadata and controls
177 lines (161 loc) · 4.43 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
import logging
import pytest
from pytest import fail
from db import DB
from models import Organizations, Domains, Users, User_affiliations
from tests.test_functions import json, run
@pytest.fixture()
def save():
save, cleanup, db_session = DB()
yield save
cleanup()
def test_get_org_resolvers_by_org_super_admin_single_node(save, caplog):
"""
Test org resolver by organization as a super admin, single node return
with all values
"""
org1 = Organizations(
acronym="ORG1",
domains=[Domains(domain="somecooldomain.ca")],
name="Organization 1",
org_tags={
"zone": "Prov",
"sector": "Banking",
"province": "Alberta",
"city": "Calgary",
},
)
save(org1)
super_admin = Users(
display_name="testsuperadmin",
user_name="testsuperadmin@testemail.ca",
password="testpassword123",
user_affiliation=[
User_affiliations(user_organization=org1, permission="super_admin")
],
)
save(super_admin)
user = Users(
display_name="testuserread",
user_name="testuserread@testemail.ca",
password="testpassword123",
user_affiliation=[
User_affiliations(user_organization=org1, permission="user_read")
],
)
save(user)
caplog.set_level(logging.INFO)
result = run(
"""
{
organization:findOrganizationDetailBySlug(slug: "organization-1") {
name
acronym
province
domains {
edges {
node {
url
}
}
}
}
}
""",
as_user=super_admin,
)
expected_result = {
"data": {
"organization": {
"name": "Organization 1",
"acronym": "ORG1",
"province": "Alberta",
"domains": {"edges": [{"node": {"url": "somecooldomain.ca"}}]},
}
}
}
if "errors" in result:
fail(
"Expected super admin to return results for all users but got: {}".format(
result["errors"]
)
)
assert result == expected_result
assert (
f"User: {super_admin.id} successfully retrieved organization info for organization-1"
in caplog.text
)
# User read tests
def test_get_org_resolvers_by_org_user_read_single_node(save, caplog):
"""
Test org resolver with an org as a user read, multi node return with
all values
"""
org1 = Organizations(
acronym="ORG1",
domains=[Domains(domain="somecooldomain.ca")],
name="Organization 1",
org_tags={
"zone": "Prov",
"sector": "Banking",
"province": "Alberta",
"city": "Calgary",
},
)
save(org1)
org2 = Organizations(
acronym="ORG2",
domains=[Domains(domain="anothercooldomain.ca")],
name="Organization 2",
org_tags={
"zone": "Muni",
"sector": "Transportation",
"province": "NS",
"city": "Halifax",
},
)
save(org2)
user = Users(
display_name="testuserread",
user_name="testuserread@testemail.ca",
password="testpassword123",
user_affiliation=[
User_affiliations(user_organization=org1, permission="user_read")
],
)
save(user)
caplog.set_level(logging.INFO)
result = run(
"""
{
organization:findOrganizationDetailBySlug(slug: "organization-1") {
name
acronym
province
domains {
edges {
node {
url
}
}
}
}
}
""",
as_user=user,
)
expected_result = {
"data": {
"organization": {
"name": "Organization 1",
"acronym": "ORG1",
"province": "Alberta",
"domains": {"edges": [{"node": {"url": "somecooldomain.ca",}}]},
}
}
}
assert result == expected_result
assert (
f"User: {user.id} successfully retrieved organization info for organization-1"
in caplog.text
)