modularise the test

This commit is contained in:
hrj 2020-07-05 00:48:20 +05:30
parent 056aa9ae70
commit 0b1e902326
1 changed files with 15 additions and 9 deletions

View File

@ -6,6 +6,7 @@ conn.request("GET", "/v1/token?email=test")
response = conn.getresponse()
responseStr = response.read()
user = json.loads(responseStr)
token = user["token"]
params = """{
"level": "medium",
@ -13,20 +14,25 @@ params = """{
"input_type": "text"
}"""
def getCaptcha():
conn.request("POST", "/v1/captcha", body=params, headers={'access-token': user["token"]})
response = conn.getresponse()
if response:
responseStr = response.read()
captcha = json.loads(responseStr)
print(captcha)
captchaId = captcha["id"]
reply = {"answer": "xyz", "id" : captchaId}
return json.loads(responseStr)
def postAnswer(captchaId, ans):
reply = {"answer": ans, "id" : captchaId}
conn.request("POST", "/v1/answer", json.dumps(reply))
response = conn.getresponse()
if response:
responseStr = response.read()
return response.read()
print(responseStr)
for i in range(0, 10000):
captcha = getCaptcha()
#print(captcha)
captchaId = captcha["id"]
print(i, postAnswer(captchaId, "xyz"))