-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_14_advanced_query.py
130 lines (126 loc) · 4.79 KB
/
test_14_advanced_query.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
import sys
import pytest
from datetime import datetime
from fastapi import FastAPI
from httpx import AsyncClient
from tests.test_01_auth import Acc
from sqlalchemy.orm import Session
from models.views.view_data import ViewData
pytestmark = pytest.mark.asyncio
sys.path.append("..")
account = Acc(True)
today = datetime.today().strftime("%B %d, %Y")
class TestAdvancedFilter():
@pytest.mark.asyncio
async def test_get_data_with_query_option(self, app: FastAPI,
session: Session,
client: AsyncClient) -> None:
data_view = session.query(ViewData).all()
data_view = [d.raw for d in data_view]
assert data_view == [
[
{"id": 4, "question": "1", "answer": "option 2"},
{"id": 4, "question": "6", "answer": "o"},
{"id": 4, "question": "6", "answer": "p"},
{"id": 4, "question": "6", "answer": "t"},
{"id": 4, "question": "6", "answer": "i"},
{"id": 4, "question": "6", "answer": "o"},
{"id": 4, "question": "6", "answer": "n"},
{"id": 4, "question": "6", "answer": " "},
{"id": 4, "question": "6", "answer": "b"},
],
[{"id": 2, "question": "1", "answer": "option 2"}],
[
{"id": 3, "question": "1", "answer": "option 1"},
{"id": 3, "question": "6", "answer": "o"},
{"id": 3, "question": "6", "answer": "p"},
{"id": 3, "question": "6", "answer": "t"},
{"id": 3, "question": "6", "answer": "i"},
{"id": 3, "question": "6", "answer": "o"},
{"id": 3, "question": "6", "answer": "n"},
{"id": 3, "question": "6", "answer": " "},
{"id": 3, "question": "6", "answer": "a"},
],
[{"id": 1, "question": "1", "answer": "option 2"}],
]
# search option 1
res = await client.get(
app.url_path_for("data:get", form_id=1),
params={"q": "1|option 1"},
headers={"Authorization": f"Bearer {account.token}"})
assert res.status_code == 200
res = res.json()
assert res["current"] == 1
assert res["total"] == 1
assert res["total_page"] == 1
assert len(res["data"]) == 1
# search option 2
res = await client.get(
app.url_path_for("data:get", form_id=1),
params={"q": "1|option 2"},
headers={"Authorization": f"Bearer {account.token}"})
assert res.status_code == 200
res = res.json()
assert res["current"] == 1
assert res["total"] == 3
assert res["total_page"] == 1
assert len(res["data"]) == 3
# search with question and administration filter
res = await client.get(
app.url_path_for("data:get", form_id=1),
params={"question": [1, 4], "administration": 10},
headers={"Authorization": f"Bearer {account.token}"})
assert res.status_code == 200
res = res.json()
assert res["current"] == 1
assert res["total"] == 2
assert res["total_page"] == 1
assert len(res["data"]) == 2
@pytest.mark.asyncio
async def test_get_maps_with_query_option(self, app: FastAPI,
session: Session,
client: AsyncClient) -> None:
res = await client.get(
app.url_path_for("maps:get", form_id=1),
params={
"marker": 1,
"shape": 2,
"hover_ids": "1|2",
"q": "1|option 2"
})
assert res.status_code == 200
res = res.json()
assert res == [{
"id": 1,
"loc": "Garut",
"geo": [-7.836114, 110.331143],
"name": "Garut - Garut",
"marker": "Option 2",
"shape": 10.0,
"marker_hover": [
{"id": 2, "value": 10.0},
{"id": 1, "value": "Option 2"}
],
}, {
"id": 2,
"loc": "Garut",
"geo": [-7.836114, 110.331143],
"name": "Garut",
"marker": "Option 2",
"shape": 10.0,
"marker_hover": [
{"id": 1, "value": "Option 2"},
{"id": 2, "value": 10.0}
],
}, {
"id": 4,
"loc": "Bantul",
"geo": [-6.2, 106.81],
"name": "Bantul - Testing Data 2",
"marker": "Option 2",
"shape": 24.0,
"marker_hover": [
{"id": 1, "value": "Option 2"},
{"id": 2, "value": 24.0}
],
}]