mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-02-06 00:38:06 -05:00
simplify locust file
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
68dcfb1e49
commit
c0ac570746
@ -24,42 +24,40 @@ class QuickStartUser(SequentialTaskSet):
|
|||||||
|
|
||||||
@task
|
@task
|
||||||
def captcha(self):
|
def captcha(self):
|
||||||
# TODO: Iterate over parameters for a more comprehensive test
|
|
||||||
captcha_params = {"level":"debug","media":"image/png","input_type":"text"}
|
captcha_params = {"level":"debug","media":"image/png","input_type":"text"}
|
||||||
|
|
||||||
resp = self.client.post(path="/v1/captcha", json=captcha_params, name="/captcha")
|
with self.client.post(path="/v1/captcha", json=captcha_params, name="/captcha", catch_response = True) as resp:
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
print("\nError on /captcha endpoint: ")
|
resp.failure("Status was not 200: " + resp.text)
|
||||||
print(resp)
|
captchaJson = resp.json()
|
||||||
print(resp.text)
|
uuid = captchaJson.get("id")
|
||||||
print("----------------END.CAPTCHA-------------------\n\n")
|
if not uuid:
|
||||||
|
resp.failure("uuid not returned on /captcha endpoint: " + resp.text)
|
||||||
|
|
||||||
uuid = resp.json().get("id")
|
with self.client.get(path="/v1/media?id=%s" % uuid, name="/media", stream=True, catch_response = True) as resp:
|
||||||
|
|
||||||
resp = self.client.get(path="/v1/media?id=%s" % uuid, name="/media", stream=True)
|
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
print("\nError on /media endpoint: ")
|
resp.failure("Status was not 200: " + resp.text)
|
||||||
print(resp)
|
|
||||||
print(resp.text)
|
|
||||||
print("----------------END.MEDIA-------------------\n\n")
|
|
||||||
|
|
||||||
media = resp.content
|
media = resp.content
|
||||||
|
|
||||||
|
ocrAnswer = self.solve(uuid, media)
|
||||||
|
|
||||||
|
answerBody = {"answer": ocrAnswer,"id": uuid}
|
||||||
|
with self.client.post(path='/v1/answer', json=answerBody, name="/answer", catch_response=True) as resp:
|
||||||
|
if resp.status_code != 200:
|
||||||
|
resp.failure("Status was not 200: " + resp.text)
|
||||||
|
else:
|
||||||
|
if resp.json().get("result") != "True":
|
||||||
|
resp.failure("Answer was not accepted")
|
||||||
|
|
||||||
|
def solve(self, uuid, media):
|
||||||
mediaFileName = "tests/test-%s.png" % uuid
|
mediaFileName = "tests/test-%s.png" % uuid
|
||||||
with open(mediaFileName, "wb") as f:
|
with open(mediaFileName, "wb") as f:
|
||||||
f.write(media)
|
f.write(media)
|
||||||
ocrResult = subprocess.Popen("gocr %s" % mediaFileName, shell=True, stdout=subprocess.PIPE)
|
ocrResult = subprocess.Popen("gocr %s" % mediaFileName, shell=True, stdout=subprocess.PIPE)
|
||||||
ocrAnswer = ocrResult.stdout.readlines()[0].strip().decode()
|
ocrAnswer = ocrResult.stdout.readlines()[0].strip().decode()
|
||||||
|
return ocrAnswer
|
||||||
|
|
||||||
answerBody = {"answer": ocrAnswer,"id": uuid}
|
|
||||||
with self.client.post(path='/v1/answer', json=answerBody, name="/answer", catch_response=True) as resp:
|
|
||||||
if resp.status_code != 200:
|
|
||||||
print("\nError on /answer endpoint: ")
|
|
||||||
print(resp)
|
|
||||||
print(resp.text)
|
|
||||||
print("----------------END.ANSWER-------------------\n\n")
|
|
||||||
else:
|
|
||||||
if resp.json().get("result") != "True":
|
|
||||||
resp.failure("Answer was not accepted")
|
|
||||||
|
|
||||||
|
|
||||||
class User(FastHttpUser):
|
class User(FastHttpUser):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user