Update test_image_to_coordinates.py
This commit is contained in:
parent
39bf93d931
commit
31bb2b53ff
|
@ -7,6 +7,7 @@ from tests.conftest import BaseTest
|
|||
from python3_anticaptcha.core.enum import SaveFormatsEnm, ResponseStatusEnm
|
||||
from python3_anticaptcha.core.serializer import GetTaskResultResponseSer
|
||||
from python3_anticaptcha.image_to_coordinates import ImageToCoordinates
|
||||
from python3_anticaptcha.core.captcha_instrument import FileInstrument
|
||||
from python3_anticaptcha.core.aio_captcha_instrument import AIOCaptchaInstrument
|
||||
from python3_anticaptcha.core.sio_captcha_instrument import SIOCaptchaInstrument
|
||||
|
||||
|
@ -46,12 +47,12 @@ class TestImageToCoordinates(BaseTest):
|
|||
def test_captcha_link(self, mocker, save_format, img_clearing):
|
||||
captured_instances = []
|
||||
mocker.patch(
|
||||
"python3_anticaptcha.image_to_coordinates.SIOCaptchaHandler",
|
||||
"python3_anticaptcha.image_to_coordinates.SIOCaptchaInstrument",
|
||||
side_effect=lambda *args, **kwargs: captured_instances.append(SIOCaptchaInstrument(*args, **kwargs))
|
||||
or captured_instances[-1],
|
||||
)
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.sio_captcha_handler.SIOCaptchaHandler.processing_captcha"
|
||||
"python3_anticaptcha.core.sio_captcha_instrument.SIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
|
||||
|
@ -69,12 +70,12 @@ class TestImageToCoordinates(BaseTest):
|
|||
async def test_aio_captcha_link(self, mocker, save_format, img_clearing):
|
||||
captured_instances = []
|
||||
mocker.patch(
|
||||
"python3_anticaptcha.image_to_coordinates.AIOCaptchaHandler",
|
||||
"python3_anticaptcha.image_to_coordinates.AIOCaptchaInstrument",
|
||||
side_effect=lambda *args, **kwargs: captured_instances.append(AIOCaptchaInstrument(*args, **kwargs))
|
||||
or captured_instances[-1],
|
||||
)
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.aio_captcha_handler.AIOCaptchaHandler.processing_captcha"
|
||||
"python3_anticaptcha.core.aio_captcha_instrument.AIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
|
||||
|
@ -89,7 +90,7 @@ class TestImageToCoordinates(BaseTest):
|
|||
|
||||
def test_err_captcha_link(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.sio_captcha_handler.SIOCaptchaHandler._url_read"
|
||||
"python3_anticaptcha.core.sio_captcha_instrument.SIOCaptchaInstrument._url_read"
|
||||
)
|
||||
mocked_method.side_effect = ValueError("Test error")
|
||||
|
||||
|
@ -104,7 +105,7 @@ class TestImageToCoordinates(BaseTest):
|
|||
|
||||
async def test_aio_err_captcha_link(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.aio_captcha_handler.AIOCaptchaHandler._url_read"
|
||||
"python3_anticaptcha.core.aio_captcha_instrument.AIOCaptchaInstrument._url_read"
|
||||
)
|
||||
mocked_method.side_effect = ValueError("Test error")
|
||||
|
||||
|
@ -118,9 +119,9 @@ class TestImageToCoordinates(BaseTest):
|
|||
assert ser_result.cost == 0.0
|
||||
|
||||
def test_captcha_base64(self, mocker):
|
||||
captcha_params_spy = mocker.spy(SIOCaptchaInstrument, "body_file_processing")
|
||||
captcha_params_spy = mocker.spy(SIOCaptchaInstrument, "processing_image_captcha")
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.sio_captcha_handler.SIOCaptchaHandler.processing_captcha"
|
||||
"python3_anticaptcha.core.sio_captcha_instrument.SIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
|
||||
|
@ -136,9 +137,9 @@ class TestImageToCoordinates(BaseTest):
|
|||
assert result == mocked_method.return_value
|
||||
|
||||
async def test_aio_captcha_base64(self, mocker):
|
||||
captcha_params_spy = mocker.spy(AIOCaptchaInstrument, "body_file_processing")
|
||||
captcha_params_spy = mocker.spy(AIOCaptchaInstrument, "processing_image_captcha")
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.aio_captcha_handler.AIOCaptchaHandler.processing_captcha"
|
||||
"python3_anticaptcha.core.aio_captcha_instrument.AIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
|
||||
|
@ -164,9 +165,32 @@ class TestImageToCoordinates(BaseTest):
|
|||
assert instance.create_task_payload.clientKey == self.API_KEY
|
||||
|
||||
def test_del(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch("shutil.rmtree")
|
||||
ImageToCoordinates(api_key=self.API_KEY, save_format=SaveFormatsEnm.CONST, img_clearing=True)
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.sio_captcha_instrument.SIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
del_method = mocker.spy(FileInstrument, "_file_clean")
|
||||
|
||||
instance = ImageToCoordinates(api_key=self.API_KEY, save_format=SaveFormatsEnm.CONST, img_clearing=True)
|
||||
result = instance.captcha_handler(captcha_link=self.captcha_url)
|
||||
|
||||
assert mocked_method.call_count == 1
|
||||
assert result == mocked_method.return_value
|
||||
assert del_method.call_count == 1
|
||||
|
||||
async def test_aio_del(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.aio_captcha_instrument.AIOCaptchaInstrument.processing_captcha"
|
||||
)
|
||||
mocked_method.return_value = "tested"
|
||||
del_method = mocker.spy(FileInstrument, "_file_clean")
|
||||
|
||||
instance = ImageToCoordinates(api_key=self.API_KEY, save_format=SaveFormatsEnm.CONST, img_clearing=True)
|
||||
result = await instance.aio_captcha_handler(captcha_link=self.captcha_url)
|
||||
|
||||
assert mocked_method.call_count == 1
|
||||
assert result == mocked_method.return_value
|
||||
assert del_method.call_count == 1
|
||||
|
||||
def test_init_kwargs(self):
|
||||
instance = ImageToCoordinates(api_key=self.API_KEY, **self.kwargs_params)
|
||||
|
@ -176,7 +200,7 @@ class TestImageToCoordinates(BaseTest):
|
|||
|
||||
def test_kwargs(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.sio_captcha_handler.SIOCaptchaHandler.body_file_processing"
|
||||
"python3_anticaptcha.core.sio_captcha_instrument.SIOCaptchaInstrument.processing_image_captcha"
|
||||
)
|
||||
|
||||
instance = ImageToCoordinates(api_key=self.API_KEY)
|
||||
|
@ -189,7 +213,7 @@ class TestImageToCoordinates(BaseTest):
|
|||
|
||||
async def test_aio_kwargs(self, mocker):
|
||||
mocked_method: MagicMock = mocker.patch(
|
||||
"python3_anticaptcha.core.aio_captcha_handler.AIOCaptchaHandler.body_file_processing"
|
||||
"python3_anticaptcha.core.aio_captcha_instrument.AIOCaptchaInstrument.processing_image_captcha"
|
||||
)
|
||||
|
||||
instance = ImageToCoordinates(api_key=self.API_KEY)
|
||||
|
|
Loading…
Reference in New Issue