python3-anticaptcha/test.py

242 lines
8.6 KiB
Python
Raw Normal View History

import asyncio
2019-02-28 00:55:04 +00:00
import requests
import python3_anticaptcha
2019-05-20 20:03:19 +00:00
from python3_anticaptcha import (
NoCaptchaTaskProxyless,
AntiCaptchaControl,
CustomCaptchaTask,
)
2019-02-28 00:55:04 +00:00
class TestAntiCaptcha(object):
def setup_class(self):
self.anticaptcha_key = "ae23fffcfaa29b170e3843e3a486ef19"
2019-05-20 20:03:19 +00:00
self.server_ip = "85.255.8.26"
2019-02-28 00:55:04 +00:00
2019-03-04 20:30:15 +00:00
# CallBack
2019-02-28 00:55:04 +00:00
def test_callback_server(self):
# test server alive
2019-05-20 20:03:19 +00:00
response = requests.get(f"http://{self.server_ip}:8001/ping")
2019-02-28 00:55:04 +00:00
assert response.status_code == 200
# try register new queue
2019-05-20 20:03:19 +00:00
response = requests.post(
f"http://{self.server_ip}:8001/register_key",
json={"key": "fwefefefopewofkewopfkop", "vhost": "anticaptcha_vhost"},
)
2019-02-28 00:55:04 +00:00
assert response.status_code == 200
2019-05-20 20:03:19 +00:00
def test_customcaptcha(self):
customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
anticaptcha_key=self.anticaptcha_key, sleep_time=10, assignment='Smth interesting'
)
# check response type
assert (
type(customcaptcha)
is python3_anticaptcha.CustomCaptchaTask.CustomCaptchaTask
)
response = customcaptcha.captcha_handler(
imageUrl=self.server_ip+'/static/image/common_image_example/088636.png',
)
# check response type
assert type(response) is dict
# check all dict keys
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
@asyncio.coroutine
def test_aiocustomcaptcha(self):
customcaptcha = CustomCaptchaTask.aioCustomCaptchaTask(
anticaptcha_key=self.anticaptcha_key, sleep_time=10, assignment='Smth interesting'
)
# check response type
assert (
type(customcaptcha)
is python3_anticaptcha.CustomCaptchaTask.aioCustomCaptchaTask
)
response = yield customcaptcha.captcha_handler(
imageUrl=self.server_ip+'/static/image/common_image_example/088636.png',
)
# check response type
assert type(response) is dict
# check all dict keys
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
def test_nocaptcha_proxyless(self):
2019-05-20 20:03:19 +00:00
nocaptcha = NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(
anticaptcha_key=self.anticaptcha_key
)
2019-02-28 00:55:04 +00:00
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(nocaptcha)
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
)
2019-02-28 00:55:04 +00:00
response = nocaptcha.captcha_handler(
2019-05-20 20:03:19 +00:00
websiteURL="https://www.google.com/recaptcha/api2/demo",
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
)
2019-02-28 00:55:04 +00:00
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
def test_nocaptcha_proxyless_context(self):
2019-05-20 20:03:19 +00:00
with NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(
anticaptcha_key=self.anticaptcha_key
) as nocaptcha:
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(nocaptcha)
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
)
response = nocaptcha.captcha_handler(
2019-05-20 20:03:19 +00:00
websiteURL="https://www.google.com/recaptcha/api2/demo",
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
@asyncio.coroutine
def test_aionocaptcha_proxyless(self):
2019-05-20 20:03:19 +00:00
nocaptcha = NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(
anticaptcha_key=self.anticaptcha_key
)
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(nocaptcha)
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
)
response = yield nocaptcha.captcha_handler(
2019-05-20 20:03:19 +00:00
websiteURL="https://www.google.com/recaptcha/api2/demo",
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
@asyncio.coroutine
def test_aionocaptcha_proxyless_context(self):
2019-05-20 20:03:19 +00:00
with NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(
anticaptcha_key=self.anticaptcha_key
) as nocaptcha:
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(nocaptcha)
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
)
response = yield nocaptcha.captcha_handler(
2019-05-20 20:03:19 +00:00
websiteURL="https://www.google.com/recaptcha/api2/demo",
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
# AntiCaptcha Control
def test_control(self):
# prepare client
2019-05-20 20:03:19 +00:00
result = AntiCaptchaControl.AntiCaptchaControl(
anticaptcha_key=self.anticaptcha_key
)
# check response type
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
2019-05-20 20:03:19 +00:00
# get balance
response = result.get_balance()
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
# complaint on result
response = result.complaint_on_result(reported_id=432423342)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
def test_control_context(self):
# prepare client
2019-05-20 20:03:19 +00:00
with AntiCaptchaControl.AntiCaptchaControl(
anticaptcha_key=self.anticaptcha_key
) as result:
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(result)
is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
)
# get balance
response = result.get_balance()
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
# complaint on result
response = result.complaint_on_result(reported_id=432423342)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
@asyncio.coroutine
def test_aiocontrol(self):
# prepare client
2019-05-20 20:03:19 +00:00
result = AntiCaptchaControl.aioAntiCaptchaControl(
anticaptcha_key=self.anticaptcha_key
)
# check response type
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
2019-05-20 20:03:19 +00:00
# get balance
response = yield result.get_balance()
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
# complaint on result
response = yield result.complaint_on_result(reported_id=432423342)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
@asyncio.coroutine
def test_aiocontrol_context(self):
# prepare client
2019-05-20 20:03:19 +00:00
with AntiCaptchaControl.aioAntiCaptchaControl(
anticaptcha_key=self.anticaptcha_key
) as result:
# check response type
2019-05-20 20:03:19 +00:00
assert (
type(result)
is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
)
# get balance
response = yield result.get_balance()
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
# complaint on result
response = yield result.complaint_on_result(reported_id=432423342)
# check response type
assert type(response) is dict
# check all dict keys
2019-05-20 20:03:19 +00:00
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())