-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.py
153 lines (124 loc) · 5.35 KB
/
handler_test.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
147
148
149
150
151
152
153
from unittest import TestCase
import requests
import json
import random
import unittest
db_host = '127.0.0.1'
db = 'points'
user = 'root'
password = 'root'
class TestPostHandler(TestCase):
def test_handler_query_limit(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select * from user limit 5'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_create_table(self):
create_table_sql = 'create table if not exists user(' \
'id_card varchar(40), name varchar(20), age int, sex varchar(5), ' \
'score int, nick_name varchar(20), comments varchar(200));'
encrypt_cols = {
"id_card": {
"fuzzy": True,
"arithmetic": False,
},
"name": {
"fuzzy": True,
"arithmetic": False
},
"age": {
"fuzzy": False,
"arithmetic": False
}
}
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': create_table_sql,
'encrypt_cols': encrypt_cols}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_insert_table(self):
for i in range(10):
query = 'insert into user(id_card, name, age, sex, score, nick_name, comments) values ( "' + str(
random.randint(1000000000000000000, 1000000000000000000000000)) + '","' + ''.join(
random.sample('zyxwvutsrqponmlkjihgfedcba', 10)) + '",' + str(random.randint(1, 50)) + ', "' + ''.join(
random.sample('fm', 1)) + '",' + str(random.randint(60, 100)) + ',"' + ''.join(
random.sample('zyxwvutsrqponmlkjihgfedcba', 10)) + '","' + ''.join(
random.sample('zyxwvutsrqpondgsghgsfgyftuywiecvdbhsbdhgshfdgsgfysgmlkjihgfedcba', 30)) + '")'
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': query}
json_data = json.dumps(content)
requests.post('http://localhost:8888/query', json_data)
def test_handler_query_where(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select id_card, name, age from user where age = 20 limit 5'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_where_and(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select id_card, name from user where id_card = "496715970993917044442778" and name = "iezlcpnjws"'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_order_by(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select id_card, name, age from user order by age limit 5'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_max(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select max(age) from user'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_min(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select min(age) from user'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_like(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select id_card, name from user where name like "rax%fpb%" limit 5'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_max1(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select max(score) from user '}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
def test_handler_query_min1(self):
content = {
'host': db_host, 'db': db,
'user': user, 'password': password,
'query': 'select min(score) from user'}
json_data = json.dumps(content)
resp = requests.post('http://localhost:8888/query', json_data)
print(resp.json()['result'])
if __name__ == "__main__":
unittest.main()