-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample_query.py
More file actions
165 lines (127 loc) · 4.37 KB
/
sample_query.py
File metadata and controls
165 lines (127 loc) · 4.37 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
import requests
import json
import sys
import argparse
HOST_PREFIX = "http://127.0.0.1:8000"
ICML_PREFIX = "{0}/icml".format(HOST_PREFIX)
USER_SECRET = '8daae7447f0d4d068429acaef5cd97bc'
def is_success(r):
if r.status_code != 200:
print r.status_code
print r.text
return r.status_code == 200
def check_registration(session):
url = '{0}/registration/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'password' : 'supersecret',
'email' : 'hptruong93@gmail.com',
}
r = session.post(url, data = data)
assert is_success(r)
return r
def check_reset_password_request(session):
url = '{0}/request_reset_password/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong'
}
r = session.post(url, data = data)
assert is_success(r)
return r
def check_password_reset(session):
url = '{0}/reset_password/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'password' : 'whitefox',
'secret' : '17f70961-bb88-4974-8674-bc790c10b2ee'
}
r = session.post(url, data = data)
assert is_success(r)
return r
############################################################################################################################
############################################End of user authentication section##############################################
############################################################################################################################
def check_post_comments(session):
url = '{0}/post_comment/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
'comment' : 'This is a test comment whose content is nothing.'
}
r1 = session.post(url, data = data)
assert is_success(r1)
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
'comment' : 'This is another test comment whose content is nothing.'
}
r2 = session.post(url, data = data)
assert is_success(r2)
return r1, r2
def check_post_comments_bis(session):
url = '{0}/post_comment/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
'comment' : 'This is the third test comment whose content is nothing.'
}
r = session.post(url, data = data)
assert is_success(r)
return r
def check_delete_comment(session, ids = []):
url = '{0}/delete_comment/'.format(ICML_PREFIX)
for the_id in ids:
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
'comment_id' : the_id
}
r = session.post(url, data = data)
assert is_success(r)
return None
def check_like_paper(session):
url = '{0}/like_paper/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
}
r = session.post(url, data = data)
assert is_success(r)
return r
def check_like_paper_bis(session):
url = '{0}/like_paper/'.format(ICML_PREFIX)
data = {
'username' : 'hptruong',
'secret' : USER_SECRET,
'paper_id' : 'the_testing_id',
}
r = session.post(url, data = data)
assert is_success(r)
return r
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Django test client')
parser.add_argument('-f', type = int, nargs = '+', dest='actions', required = True, default = [0], help = 'Action to take')
args = parser.parse_args()
session = requests.Session()
if 0 in args.actions:
check_registration(session)
if 1 in args.actions:
response = check_reset_password_request(session)
if 2 in args.actions:
check_password_reset(session)
if 3 in args.actions:
r1, r2 = check_post_comments(session)
comment_id1 = r1.json()['id']
comment_id2 = r2.json()['id']
comment_id3 = check_post_comments_bis(session).json()['id']
if 4 in args.actions:
check_delete_comment(session, [comment_id1, comment_id3])
if 5 in args.actions:
check_delete_comment(session, [comment_id2])
if 6 in args.actions:
check_like_paper(session)