-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_18_hint.py
146 lines (143 loc) · 4.36 KB
/
test_18_hint.py
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
import sys
import pytest
from fastapi import FastAPI
from httpx import AsyncClient
from tests.test_01_auth import Acc
from sqlalchemy.orm import Session
from db.crud_question import get_question_by_id
from models.question import QuestionType
from datetime import datetime
pytestmark = pytest.mark.asyncio
sys.path.append("..")
account = Acc(True)
today = datetime.today().strftime("%B %d, %Y")
class TestHintRoutes():
@pytest.mark.asyncio
async def test_get_hint(
self, app: FastAPI, session: Session, client: AsyncClient) -> None:
# get hint when no data
question = get_question_by_id(session=session, id=5)
question = question.serialize
assert question["type"] == QuestionType.number
res = await client.get(
app.url_path_for("hint:get", question_id=question["id"]))
assert res.status_code == 200
res = res.json()
assert res == {
'mean': None,
'q1': None,
'q2': None,
'q3': None,
'max': None,
'min': None
}
# submit data with number
res = await client.post(
app.url_path_for("data:create", form_id=1),
json=[{
"question": 1,
"value": "Option 1"
}, {
"question": 2,
"value": [2, 10]
}, {
"question": 3,
"value": {
"lat": -7.836114,
"lng": 110.331143
}
}, {
"question": 4,
"value": "Hint Test"
}, {
"question": 5,
"value": 45
}, {
"question": 6,
"value": ["Option A", "Option B"]
}, {
"question": 7,
"value": "2021-12-21"
}],
headers={"Authorization": f"Bearer {account.token}"})
assert res.status_code == 200
res = res.json()
assert res == {
"id": 5,
"name": "Garut - Hint Test",
"administration": 10,
"created": today,
"created_by": "Akvo Support",
"form": 1,
"geo": {
"lat": -7.836114,
"long": 110.331143
},
"updated": None,
"updated_by": None,
"answer": [{
"question": 1,
"value": "Option 1"
}, {
"question": 2,
"value": 10
}, {
"question": 3,
"value": "-7.836114|110.331143"
}, {
"question": 4,
"value": "Hint Test"
}, {
"question": 5,
"value": 45
}, {
"question": 6,
"value": ["Option A", "Option B"]
}, {
"question": 7,
"value": "2021-12-21"
}]
}
# assert second data
res = await client.post(
app.url_path_for("data:create", form_id=1),
json=[{
"question": 1,
"value": "Option 2"
}, {
"question": 2,
"value": [2, 10]
}, {
"question": 3,
"value": {
"lat": -7.836114,
"lng": 110.331143
}
}, {
"question": 4,
"value": "Hint Test"
}, {
"question": 5,
"value": 55
}, {
"question": 6,
"value": ["Option B"]
}, {
"question": 7,
"value": "2022-10-10"
}],
headers={"Authorization": f"Bearer {account.token}"})
assert res.status_code == 200
# get hint
res = await client.get(
app.url_path_for("hint:get", question_id=question["id"]))
assert res.status_code == 200
res = res.json()
assert res == {
'mean': 'Average value is 50.0',
'q1': 'First quantile value is 47.5',
'q2': 'Second quantile value is 50.0',
'q3': 'Third quantile value is 52.5',
'max': 'Maximum value is 55.0',
'min': 'Minimum value is 45.0'
}