Skip to content

Commit

Permalink
added more FunCaptcha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Nov 10, 2022
1 parent 5383a77 commit a8f6c0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/python3_captchaai/fun_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion src/tests/test_fun_captcha.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pydantic import ValidationError

from src.tests.conftest import BaseTest
from python3_captchaai.core.enum import CaptchaTypeEnm
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a8f6c0b

Please sign in to comment.