python3-anticaptcha/tests/test_CustomResultHandler.py

162 lines
5.4 KiB
Python
Raw Normal View History

2019-09-05 21:07:36 +00:00
import inspect
import pytest
from python3_anticaptcha import CustomResultHandler
2019-09-29 22:11:51 +00:00
from tests.main import MainAntiCaptcha
2019-09-05 21:07:36 +00:00
class TestAntiCaptcha(MainAntiCaptcha):
"""
Params check
"""
def test_result_handler_params(self):
default_init_params = ["self", "anticaptcha_key", "sleep_time"]
default_handler_params = ["self", "task_id"]
# get customcaptcha init and task_handler params
aioinit_params = inspect.getfullargspec(
CustomResultHandler.aioCustomResultHandler.__init__
)
aiohandler_params = inspect.getfullargspec(
CustomResultHandler.aioCustomResultHandler.task_handler
)
# get customcaptcha init and task_handler params
2019-11-25 17:08:18 +00:00
init_params = inspect.getfullargspec(CustomResultHandler.CustomResultHandler.__init__)
2019-09-05 21:07:36 +00:00
handler_params = inspect.getfullargspec(
CustomResultHandler.CustomResultHandler.task_handler
)
# check aio module params
assert default_init_params == aioinit_params[0]
assert default_handler_params == aiohandler_params[0]
# check sync module params
assert default_init_params == init_params[0]
assert default_handler_params == handler_params[0]
"""
Response checking
"""
def test_response_result_handler(self):
# prepare client
custom_result = CustomResultHandler.CustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
)
2019-09-07 01:31:37 +00:00
# check response type
assert isinstance(custom_result, CustomResultHandler.CustomResultHandler)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check response type
2019-09-07 01:31:37 +00:00
assert isinstance(response, dict)
2019-09-05 21:07:36 +00:00
# check all dict keys
2019-11-25 17:08:18 +00:00
assert ["errorId", "errorCode", "errorDescription", "taskId"] == list(response.keys())
2019-09-05 21:07:36 +00:00
@pytest.mark.asyncio
async def test_response_aioresult_handler(self):
# prepare client
custom_result = CustomResultHandler.aioCustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
)
2019-09-07 01:31:37 +00:00
# check response type
assert isinstance(custom_result, CustomResultHandler.aioCustomResultHandler)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = await custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check response type
2019-09-07 01:31:37 +00:00
assert isinstance(response, dict)
2019-09-05 21:07:36 +00:00
# check all dict keys
2019-11-25 17:08:18 +00:00
assert ["errorId", "errorCode", "errorDescription", "taskId"] == list(response.keys())
2019-09-05 21:07:36 +00:00
"""
Fail tests
"""
def test_fail_result_handler(self):
# prepare client
custom_result = CustomResultHandler.CustomResultHandler(
anticaptcha_key=self.anticaptcha_key_fail
)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 1 == response["errorId"]
def test_fail_result_handler_context(self):
# prepare client
with CustomResultHandler.CustomResultHandler(
anticaptcha_key=self.anticaptcha_key_fail
) as custom_result:
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 1 == response["errorId"]
@pytest.mark.asyncio
async def test_fail_aioresult_handler(self):
# prepare client
custom_result = CustomResultHandler.aioCustomResultHandler(
anticaptcha_key=self.anticaptcha_key_fail
)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = await custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 1 == response["errorId"]
@pytest.mark.asyncio
async def test_fail_aioresult_handler_context(self):
# prepare client
with CustomResultHandler.aioCustomResultHandler(
anticaptcha_key=self.anticaptcha_key_fail
) as custom_result:
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = await custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 1 == response["errorId"]
"""
True tests
"""
def test_true_result_handler(self):
# prepare client
custom_result = CustomResultHandler.CustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 16 == response["errorId"]
def test_true_result_handler_context(self):
# prepare client
with CustomResultHandler.CustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
) as custom_result:
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 16 == response["errorId"]
@pytest.mark.asyncio
async def test_true_aioresult_handler(self):
# prepare client
custom_result = CustomResultHandler.aioCustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
)
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = await custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 16 == response["errorId"]
@pytest.mark.asyncio
async def test_true_aioresult_handler_context(self):
# prepare client
with CustomResultHandler.aioCustomResultHandler(
anticaptcha_key=self.anticaptcha_key_true
) as custom_result:
2019-09-11 01:09:56 +00:00
2019-09-05 21:07:36 +00:00
response = await custom_result.task_handler(task_id=self.WRONG_TASK_ID)
# check error code
assert 16 == response["errorId"]