diff --git a/src/python3_captchaai/fun_captcha.py b/src/python3_captchaai/fun_captcha.py index a9f73fac..459e3708 100644 --- a/src/python3_captchaai/fun_captcha.py +++ b/src/python3_captchaai/fun_captcha.py @@ -180,7 +180,7 @@ def captcha_handler( """ # validation of the received parameters for FunCaptchaClassification if self.captcha_type == CaptchaTypeEnm.FunCaptchaClassification: - if not image and not question: + if not image or not question: raise ValueError( f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, available - {CaptchaTypeEnm.FuncaptchaTaskProxyless.value, @@ -265,7 +265,7 @@ async def aio_captcha_handler( """ # validation of the received parameters for FunCaptchaClassification if self.captcha_type == CaptchaTypeEnm.FunCaptchaClassification: - if not image and not question: + if not image or not question: raise ValueError( f"""Invalid `captcha_type` parameter set for `{self.__class__.__name__}`, available - {CaptchaTypeEnm.FuncaptchaTaskProxyless.value, diff --git a/src/tests/test_fun_captcha.py b/src/tests/test_fun_captcha.py index 56ee01e4..812ef7d6 100644 --- a/src/tests/test_fun_captcha.py +++ b/src/tests/test_fun_captcha.py @@ -1,4 +1,5 @@ import pytest +from pydantic import ValidationError from src.tests.conftest import BaseTest from python3_captchaai.core.enum import CaptchaTypeEnm @@ -30,7 +31,17 @@ def test_wrong_captcha_type(self): websiteURL=websiteURL, websitePublicKey=websitePublicKey, funcaptchaApiJSSubdomain=funcaptchaApiJSSubdomain, - ) + ).captcha_handler() + + @pytest.mark.parametrize("captcha_type", captcha_types) + def test_wrong_type_params(self, captcha_type: str): + with pytest.raises(expected_exception=(ValidationError, ValueError)): + FunCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type).captcha_handler() + + @pytest.mark.parametrize("captcha_type", captcha_types) + async def test_aio_wrong_type_params(self, captcha_type: str): + with pytest.raises(expected_exception=(ValidationError, ValueError)): + await FunCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type).aio_captcha_handler() def test_no_captcha_type(self): with pytest.raises(TypeError):