diff --git a/tests/test_image_captcha.py b/tests/test_image_captcha.py index 0804737..9da51db 100644 --- a/tests/test_image_captcha.py +++ b/tests/test_image_captcha.py @@ -1,5 +1,8 @@ +from unittest.mock import AsyncMock, MagicMock + from tests.conftest import BaseTest from python3_anticaptcha.image_captcha import ImageToTextCaptcha +from python3_anticaptcha.core.serializer import GetTaskResultResponseSer class TestImageCaptcha(BaseTest): @@ -27,3 +30,47 @@ class TestImageCaptcha(BaseTest): def test_args(self): instance = ImageToTextCaptcha(api_key=self.API_KEY) assert instance.create_task_payload.clientKey == self.API_KEY + + def test_kwargs(self, mocker): + mocked_method: MagicMock = mocker.patch("python3_anticaptcha.core.base.BaseCaptcha._body_file_processing") + + instance = ImageToTextCaptcha(api_key=self.API_KEY) + instance.captcha_handler(**self.kwargs_params) + + assert mocked_method.call_count == 1 + + assert set(self.kwargs_params.keys()).issubset(set(instance.task_params.keys())) + assert set(self.kwargs_params.values()).issubset(set(instance.task_params.values())) + + async def test_aio_kwargs(self, mocker): + mocked_method: AsyncMock = mocker.patch("python3_anticaptcha.core.base.BaseCaptcha._aio_body_file_processing") + + instance = ImageToTextCaptcha(api_key=self.API_KEY) + await instance.aio_captcha_handler(**self.kwargs_params) + + assert mocked_method.call_count == 1 + + assert set(self.kwargs_params.keys()).issubset(set(instance.task_params.keys())) + assert set(self.kwargs_params.values()).issubset(set(instance.task_params.values())) + + def test_result_with_errorId(self, mocker): + mocked_method: MagicMock = mocker.patch("python3_anticaptcha.core.base.BaseCaptcha._body_file_processing") + + instance = ImageToTextCaptcha(api_key=self.API_KEY) + instance.result.errorId = 1 + result = instance.captcha_handler(**self.kwargs_params) + + assert mocked_method.call_count == 1 + assert isinstance(result, dict) + assert result == GetTaskResultResponseSer(**result).to_dict() + + async def test_aio_result_with_errorId(self, mocker): + mocked_method: AsyncMock = mocker.patch("python3_anticaptcha.core.base.BaseCaptcha._aio_body_file_processing") + + instance = ImageToTextCaptcha(api_key=self.API_KEY) + instance.result.errorId = 1 + result = await instance.aio_captcha_handler(**self.kwargs_params) + + assert mocked_method.call_count == 1 + assert isinstance(result, dict) + assert result == GetTaskResultResponseSer(**result).to_dict()