forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cost_check.py
More file actions
102 lines (91 loc) · 2.53 KB
/
Copy pathtest_cost_check.py
File metadata and controls
102 lines (91 loc) · 2.53 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
import pytest
from db import DB
from models import Users
from tests.test_functions import json, run
from backend.security_check import SecurityAnalysisBackend
@pytest.fixture()
def save():
s, cleanup, db_session = DB()
yield s
cleanup()
def test_valid_cost_query(save):
"""
Test cost check function operates normally with valid query
"""
test_super_admin = Users(
display_name="testsuperadmin",
user_name="testsuperadmin@testemail.ca",
password="testpassword123",
)
save(test_super_admin)
result = run(
query="""
{
user {
displayName
}
}
""",
as_user=test_super_admin,
)
expected = {"data": {"user": [{"displayName": "testsuperadmin"}]}}
assert result == expected
def test_invalid_cost_query(save):
"""
Test cost check function detects that cost is too high
"""
test_super_admin = Users(
id=2,
display_name="testsuperadmin",
user_name="testsuperadmin@testemail.ca",
password="testpassword123",
)
save(test_super_admin)
result = run(
query="""
{
getSectorById(id: 1) {
groups {
edges {
node {
sectorId
}
}
}
groups {
edges {
node {
sectorId
}
}
}
groups {
edges {
node {
sectorId
}
}
}
groups {
edges {
node {
sectorId
}
}
}
groups {
edges {
node {
sectorId
}
}
}
}
}
""",
as_user=test_super_admin,
backend=SecurityAnalysisBackend(10, 5),
)
assert result["errors"]
assert result["errors"][0]
assert result["errors"][0]["message"] == "Query cost is too high"