2019-10-03 19:52:30 +00:00
|
|
|
import inspect
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from python3_anticaptcha import AntiCaptchaControl
|
|
|
|
|
|
|
|
from tests.main import MainAntiCaptcha
|
|
|
|
|
|
|
|
|
|
|
|
class TestAntiCaptcha(MainAntiCaptcha):
|
|
|
|
WRONG_SAVE_FORMAT = "qwerty"
|
|
|
|
"""
|
|
|
|
Params check
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_customcatpcha_params(self):
|
|
|
|
default_init_params = [
|
|
|
|
"self",
|
|
|
|
"anticaptcha_key",
|
|
|
|
]
|
|
|
|
default_get_balance_params = [
|
|
|
|
"self",
|
|
|
|
]
|
|
|
|
default_app_stats_params = [
|
|
|
|
"self",
|
|
|
|
"softId",
|
|
|
|
"mode",
|
|
|
|
]
|
|
|
|
default_complaint_params = [
|
|
|
|
"self",
|
|
|
|
"reported_id",
|
|
|
|
"captcha_type"
|
|
|
|
]
|
|
|
|
default_queue_status_params = [
|
|
|
|
"self",
|
|
|
|
"queue_id"
|
|
|
|
]
|
2019-10-04 10:39:40 +00:00
|
|
|
# get aiocaptchacontrol init and other params
|
|
|
|
aio_init_params = inspect.getfullargspec(
|
2019-10-03 19:52:30 +00:00
|
|
|
AntiCaptchaControl.aioAntiCaptchaControl.__init__
|
|
|
|
)
|
2019-10-04 10:39:40 +00:00
|
|
|
aio_balance_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.aioAntiCaptchaControl.get_balance
|
|
|
|
)
|
|
|
|
aio_app_stats_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.aioAntiCaptchaControl.get_app_stats
|
|
|
|
)
|
|
|
|
aio_complaint_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.aioAntiCaptchaControl.complaint_on_result
|
|
|
|
)
|
|
|
|
aio_queue_status_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.aioAntiCaptchaControl.get_queue_status
|
2019-10-03 19:52:30 +00:00
|
|
|
)
|
|
|
|
|
2019-10-04 10:39:40 +00:00
|
|
|
# get captchacontrol init and other params
|
|
|
|
init_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.AntiCaptchaControl.__init__
|
|
|
|
)
|
|
|
|
balance_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.AntiCaptchaControl.get_balance
|
|
|
|
)
|
|
|
|
app_stats_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.AntiCaptchaControl.get_app_stats
|
|
|
|
)
|
|
|
|
complaint_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.AntiCaptchaControl.complaint_on_result
|
|
|
|
)
|
|
|
|
queue_status_params = inspect.getfullargspec(
|
|
|
|
AntiCaptchaControl.AntiCaptchaControl.get_queue_status
|
2019-10-03 19:52:30 +00:00
|
|
|
)
|
|
|
|
# check aio module params
|
2019-10-04 10:39:40 +00:00
|
|
|
assert default_init_params == aio_init_params[0]
|
|
|
|
assert default_get_balance_params == aio_balance_params[0]
|
|
|
|
assert default_app_stats_params == aio_app_stats_params[0]
|
|
|
|
assert default_complaint_params == aio_complaint_params[0]
|
|
|
|
assert default_queue_status_params == aio_queue_status_params[0]
|
2019-10-03 19:52:30 +00:00
|
|
|
# check sync module params
|
|
|
|
assert default_init_params == init_params[0]
|
2019-10-04 10:39:40 +00:00
|
|
|
assert default_get_balance_params == balance_params[0]
|
|
|
|
assert default_app_stats_params == app_stats_params[0]
|
|
|
|
assert default_complaint_params == complaint_params[0]
|
|
|
|
assert default_queue_status_params == queue_status_params[0]
|
2019-10-03 19:52:30 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Response checking
|
|
|
|
"""
|
|
|
|
|
2019-10-04 10:39:40 +00:00
|
|
|
def test_response_control(self):
|
2019-10-03 19:52:30 +00:00
|
|
|
control_captcha = AntiCaptchaControl.AntiCaptchaControl(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail
|
|
|
|
)
|
|
|
|
# check response type
|
|
|
|
assert isinstance(control_captcha, AntiCaptchaControl.AntiCaptchaControl)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_response_aioimagecaptcha(self):
|
2019-10-04 10:39:40 +00:00
|
|
|
imagecaptcha = AntiCaptchaControl.aioAntiCaptchaControl(
|
2019-10-03 19:52:30 +00:00
|
|
|
anticaptcha_key=self.anticaptcha_key_fail
|
|
|
|
)
|
|
|
|
# check response type
|
2019-10-04 10:39:40 +00:00
|
|
|
assert isinstance(imagecaptcha, AntiCaptchaControl.aioAntiCaptchaControl)
|
2019-10-03 19:52:30 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Fail tests
|
|
|
|
"""
|
|
|
|
|
|
|
|
def test_fail_imagecaptcha_value(self):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
assert ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=self.WRONG_SAVE_FORMAT,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_fail_imagecaptcha_const(self):
|
|
|
|
imagecaptcha = ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[0],
|
|
|
|
)
|
|
|
|
|
|
|
|
response = imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
def test_fail_imagecaptcha_const_context(self):
|
|
|
|
with ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[0],
|
|
|
|
) as imagecaptcha:
|
|
|
|
|
|
|
|
response = imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
def test_fail_imagecaptcha_temp(self):
|
|
|
|
imagecaptcha = ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[1],
|
|
|
|
)
|
|
|
|
|
|
|
|
response = imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
def test_fail_imagecaptcha_temp_context(self):
|
|
|
|
with ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[1],
|
|
|
|
) as imagecaptcha:
|
|
|
|
|
|
|
|
response = imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_fail_aioimagecaptcha_value(self):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
assert ImageToTextTask.ImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=self.WRONG_SAVE_FORMAT,
|
|
|
|
)
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_fail_aioimagecaptcha_temp(self):
|
|
|
|
imagecaptcha = ImageToTextTask.aioImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[1],
|
|
|
|
)
|
|
|
|
response = await imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_fail_aioimagecaptcha_temp_context(self):
|
|
|
|
with ImageToTextTask.aioImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[1],
|
|
|
|
) as imagecaptcha:
|
|
|
|
response = await imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_fail_aioimagecaptcha_const(self):
|
|
|
|
imagecaptcha = ImageToTextTask.aioImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[0],
|
|
|
|
)
|
|
|
|
response = await imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_fail_aioimagecaptcha_const_context(self):
|
|
|
|
with ImageToTextTask.aioImageToTextTask(
|
|
|
|
anticaptcha_key=self.anticaptcha_key_fail,
|
|
|
|
save_format=ImageToTextTask.SAVE_FORMATS[0],
|
|
|
|
) as imagecaptcha:
|
|
|
|
response = await imagecaptcha.captcha_handler(captcha_link=self.image_url)
|
|
|
|
assert 1 == response["errorId"]
|
|
|
|
|
|
|
|
"""
|
|
|
|
True tests
|
|
|
|
"""
|