Add CustomCaptcha tests. Refactor.
This commit is contained in:
parent
3ac9bb48af
commit
2b1d347ff8
161
test.py
161
test.py
|
@ -3,89 +3,152 @@ import asyncio
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import python3_anticaptcha
|
import python3_anticaptcha
|
||||||
from python3_anticaptcha import NoCaptchaTaskProxyless, AntiCaptchaControl
|
from python3_anticaptcha import (
|
||||||
|
NoCaptchaTaskProxyless,
|
||||||
|
AntiCaptchaControl,
|
||||||
|
CustomCaptchaTask,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestAntiCaptcha(object):
|
class TestAntiCaptcha(object):
|
||||||
def setup_class(self):
|
def setup_class(self):
|
||||||
#def __init__(self):
|
|
||||||
self.anticaptcha_key = "ae23fffcfaa29b170e3843e3a486ef19"
|
self.anticaptcha_key = "ae23fffcfaa29b170e3843e3a486ef19"
|
||||||
self.server_ip = '85.255.8.26'
|
self.server_ip = "85.255.8.26"
|
||||||
|
|
||||||
# CallBack
|
# CallBack
|
||||||
def test_callback_server(self):
|
def test_callback_server(self):
|
||||||
# test server alive
|
# test server alive
|
||||||
response = requests.get(f'http://{self.server_ip}:8001/ping')
|
response = requests.get(f"http://{self.server_ip}:8001/ping")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
# try register new queue
|
# try register new queue
|
||||||
response = requests.post(f'http://{self.server_ip}:8001/register_key',
|
response = requests.post(
|
||||||
json={'key':'fwefefefopewofkewopfkop',
|
f"http://{self.server_ip}:8001/register_key",
|
||||||
'vhost':'anticaptcha_vhost'}
|
json={"key": "fwefefefopewofkewopfkop", "vhost": "anticaptcha_vhost"},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
def test_nocaptcha_proxyless(self):
|
def test_customcaptcha(self):
|
||||||
nocaptcha = NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(anticaptcha_key = self.anticaptcha_key)
|
customcaptcha = CustomCaptchaTask.CustomCaptchaTask(
|
||||||
|
anticaptcha_key=self.anticaptcha_key, sleep_time=10, assignment='Smth interesting'
|
||||||
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(nocaptcha) is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
assert (
|
||||||
|
type(customcaptcha)
|
||||||
|
is python3_anticaptcha.CustomCaptchaTask.CustomCaptchaTask
|
||||||
|
)
|
||||||
|
|
||||||
response = nocaptcha.captcha_handler(
|
response = customcaptcha.captcha_handler(
|
||||||
websiteURL='https://www.google.com/recaptcha/api2/demo',
|
imageUrl=self.server_ip+'/static/image/common_image_example/088636.png',
|
||||||
websiteKey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'
|
|
||||||
)
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.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):
|
||||||
|
nocaptcha = NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
)
|
||||||
|
# check response type
|
||||||
|
assert (
|
||||||
|
type(nocaptcha)
|
||||||
|
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
||||||
|
)
|
||||||
|
|
||||||
|
response = nocaptcha.captcha_handler(
|
||||||
|
websiteURL="https://www.google.com/recaptcha/api2/demo",
|
||||||
|
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
|
||||||
|
)
|
||||||
|
# check response type
|
||||||
|
assert type(response) is dict
|
||||||
|
# check all dict keys
|
||||||
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
def test_nocaptcha_proxyless_context(self):
|
def test_nocaptcha_proxyless_context(self):
|
||||||
with NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(anticaptcha_key = self.anticaptcha_key) as nocaptcha:
|
with NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
) as nocaptcha:
|
||||||
|
|
||||||
# check response type
|
# check response type
|
||||||
assert type(nocaptcha) is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
assert (
|
||||||
|
type(nocaptcha)
|
||||||
|
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
||||||
|
)
|
||||||
|
|
||||||
response = nocaptcha.captcha_handler(
|
response = nocaptcha.captcha_handler(
|
||||||
websiteURL='https://www.google.com/recaptcha/api2/demo',
|
websiteURL="https://www.google.com/recaptcha/api2/demo",
|
||||||
websiteKey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'
|
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
|
||||||
)
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_aionocaptcha_proxyless(self):
|
def test_aionocaptcha_proxyless(self):
|
||||||
nocaptcha = NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(anticaptcha_key=self.anticaptcha_key)
|
nocaptcha = NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(nocaptcha) is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
assert (
|
||||||
|
type(nocaptcha)
|
||||||
|
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
||||||
|
)
|
||||||
|
|
||||||
response = yield nocaptcha.captcha_handler(
|
response = yield nocaptcha.captcha_handler(
|
||||||
websiteURL='https://www.google.com/recaptcha/api2/demo',
|
websiteURL="https://www.google.com/recaptcha/api2/demo",
|
||||||
websiteKey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'
|
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
|
||||||
)
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_aionocaptcha_proxyless_context(self):
|
def test_aionocaptcha_proxyless_context(self):
|
||||||
with NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(anticaptcha_key=self.anticaptcha_key) as nocaptcha:
|
with NoCaptchaTaskProxyless.aioNoCaptchaTaskProxyless(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
) as nocaptcha:
|
||||||
# check response type
|
# check response type
|
||||||
assert type(nocaptcha) is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
assert (
|
||||||
|
type(nocaptcha)
|
||||||
|
is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
|
||||||
|
)
|
||||||
|
|
||||||
response = yield nocaptcha.captcha_handler(
|
response = yield nocaptcha.captcha_handler(
|
||||||
websiteURL='https://www.google.com/recaptcha/api2/demo',
|
websiteURL="https://www.google.com/recaptcha/api2/demo",
|
||||||
websiteKey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'
|
websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
|
||||||
)
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
# AntiCaptcha Control
|
# AntiCaptcha Control
|
||||||
def test_control(self):
|
def test_control(self):
|
||||||
# prepare client
|
# prepare client
|
||||||
result = AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key = self.anticaptcha_key)
|
result = AntiCaptchaControl.AntiCaptchaControl(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
||||||
|
|
||||||
|
@ -94,39 +157,46 @@ class TestAntiCaptcha(object):
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
# complaint on result
|
# complaint on result
|
||||||
response = result.complaint_on_result(reported_id=432423342)
|
response = result.complaint_on_result(reported_id=432423342)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
def test_control_context(self):
|
def test_control_context(self):
|
||||||
# prepare client
|
# prepare client
|
||||||
with AntiCaptchaControl.AntiCaptchaControl(anticaptcha_key = self.anticaptcha_key) as result:
|
with AntiCaptchaControl.AntiCaptchaControl(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
) as result:
|
||||||
# check response type
|
# check response type
|
||||||
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
assert (
|
||||||
|
type(result)
|
||||||
|
is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
||||||
|
)
|
||||||
|
|
||||||
# get balance
|
# get balance
|
||||||
response = result.get_balance()
|
response = result.get_balance()
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
# complaint on result
|
# complaint on result
|
||||||
response = result.complaint_on_result(reported_id=432423342)
|
response = result.complaint_on_result(reported_id=432423342)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_aiocontrol(self):
|
def test_aiocontrol(self):
|
||||||
# prepare client
|
# prepare client
|
||||||
result = AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key = self.anticaptcha_key)
|
result = AntiCaptchaControl.aioAntiCaptchaControl(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
||||||
|
|
||||||
|
@ -135,32 +205,37 @@ class TestAntiCaptcha(object):
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
# complaint on result
|
# complaint on result
|
||||||
response = yield result.complaint_on_result(reported_id=432423342)
|
response = yield result.complaint_on_result(reported_id=432423342)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_aiocontrol_context(self):
|
def test_aiocontrol_context(self):
|
||||||
# prepare client
|
# prepare client
|
||||||
with AntiCaptchaControl.aioAntiCaptchaControl(anticaptcha_key = self.anticaptcha_key) as result:
|
with AntiCaptchaControl.aioAntiCaptchaControl(
|
||||||
|
anticaptcha_key=self.anticaptcha_key
|
||||||
|
) as result:
|
||||||
# check response type
|
# check response type
|
||||||
assert type(result) is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
assert (
|
||||||
|
type(result)
|
||||||
|
is python3_anticaptcha.AntiCaptchaControl.AntiCaptchaControl
|
||||||
|
)
|
||||||
|
|
||||||
# get balance
|
# get balance
|
||||||
response = yield result.get_balance()
|
response = yield result.get_balance()
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
||||||
# complaint on result
|
# complaint on result
|
||||||
response = yield result.complaint_on_result(reported_id=432423342)
|
response = yield result.complaint_on_result(reported_id=432423342)
|
||||||
# check response type
|
# check response type
|
||||||
assert type(response) is dict
|
assert type(response) is dict
|
||||||
# check all dict keys
|
# check all dict keys
|
||||||
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())
|
assert ["errorId", "errorCode", "errorDescription"] == list(response.keys())
|
||||||
|
|
Loading…
Reference in New Issue