2024-12-15 23:25:40 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from tests.conftest import BaseTest
|
|
|
|
from python3_anticaptcha.gee_test import GeeTest
|
|
|
|
from python3_anticaptcha.core.enum import ProxyTypeEnm, CaptchaTypeEnm
|
|
|
|
from python3_anticaptcha.core.serializer import GetTaskResultResponseSer
|
|
|
|
|
|
|
|
|
2024-12-15 23:27:19 +00:00
|
|
|
class GeeTestBase(BaseTest):
|
2024-12-15 23:25:40 +00:00
|
|
|
websiteURL = "https://www.geetest.com/en/adaptive-captcha-demo"
|
|
|
|
gt = "81388ea1fc187e0c335c0a8907ff2625"
|
|
|
|
challenge = "12345678abc90123d45678ef90123a456b"
|
2024-12-15 23:27:41 +00:00
|
|
|
version = 0
|
2024-12-15 23:25:40 +00:00
|
|
|
|
|
|
|
def get_proxy_args(self) -> dict:
|
|
|
|
proxy_args = super().get_proxy_args()
|
|
|
|
proxy_args.update({"userAgent": self.get_random_string()})
|
|
|
|
return proxy_args
|
2024-12-15 23:27:41 +00:00
|
|
|
|
2024-12-15 23:25:40 +00:00
|
|
|
def test_sio_success(self):
|
|
|
|
instance = GeeTest(
|
|
|
|
api_key=self.API_KEY,
|
|
|
|
websiteURL=self.websiteURL,
|
|
|
|
gt=self.gt,
|
|
|
|
challenge=self.challenge,
|
|
|
|
version=self.version,
|
|
|
|
captcha_type=CaptchaTypeEnm.GeeTestTaskProxyless,
|
|
|
|
)
|
|
|
|
result = instance.captcha_handler()
|
|
|
|
|
|
|
|
assert isinstance(result, dict)
|
|
|
|
ser_result = GetTaskResultResponseSer(**result)
|
2024-12-15 23:31:00 +00:00
|
|
|
assert ser_result.errorId in (34, 12)
|
2024-12-15 23:25:40 +00:00
|
|
|
|
|
|
|
async def test_aio_success(self):
|
|
|
|
instance = GeeTest(
|
|
|
|
api_key=self.API_KEY,
|
|
|
|
websiteURL=self.websiteURL,
|
|
|
|
gt=self.gt,
|
|
|
|
challenge=self.challenge,
|
|
|
|
version=self.version,
|
|
|
|
captcha_type=CaptchaTypeEnm.GeeTestTaskProxyless,
|
|
|
|
)
|
|
|
|
result = await instance.aio_captcha_handler()
|
|
|
|
|
|
|
|
assert isinstance(result, dict)
|
|
|
|
ser_result = GetTaskResultResponseSer(**result)
|
2024-12-15 23:31:00 +00:00
|
|
|
assert ser_result.errorId in (34, 12)
|
2024-12-15 23:25:40 +00:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("proxyType", ProxyTypeEnm)
|
|
|
|
def test_proxy_args(self, proxyType: ProxyTypeEnm):
|
|
|
|
proxy_args = self.get_proxy_args()
|
|
|
|
proxy_args.update({"proxyType": proxyType})
|
|
|
|
|
|
|
|
instance = GeeTest(
|
|
|
|
api_key=self.API_KEY,
|
|
|
|
websiteURL=self.websiteURL,
|
|
|
|
gt=self.gt,
|
|
|
|
challenge=self.challenge,
|
|
|
|
version=self.version,
|
|
|
|
captcha_type=CaptchaTypeEnm.GeeTestTask,
|
|
|
|
**proxy_args,
|
|
|
|
)
|
|
|
|
for key, value in proxy_args.items():
|
|
|
|
assert instance.task_params[key] == value
|
|
|
|
|
|
|
|
def test_err_captcha_type(self):
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
GeeTest(
|
|
|
|
api_key=self.API_KEY,
|
|
|
|
websiteURL=self.websiteURL,
|
|
|
|
gt=self.gt,
|
|
|
|
challenge=self.challenge,
|
|
|
|
version=self.version,
|
|
|
|
captcha_type=self.get_random_string(length=10),
|
|
|
|
)
|
2024-12-15 23:27:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestGeeTestV3(GeeTestBase):
|
|
|
|
version = 3
|
|
|
|
|
|
|
|
|
|
|
|
class TestGeeTestV4(GeeTestBase):
|
|
|
|
version = 4
|