From d95dfa4671d19fa60744c8a6d62382235a44a3f8 Mon Sep 17 00:00:00 2001 From: Andrei Date: Sun, 15 Dec 2024 23:04:12 +0300 Subject: [PATCH] Create test_turnstile.py --- tests/test_turnstile.py | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_turnstile.py diff --git a/tests/test_turnstile.py b/tests/test_turnstile.py new file mode 100644 index 0000000..8c2cf9b --- /dev/null +++ b/tests/test_turnstile.py @@ -0,0 +1,64 @@ +import pytest + +from tests.conftest import BaseTest +from python3_anticaptcha.core.enum import ProxyTypeEnm, CaptchaTypeEnm +from python3_anticaptcha.turnstile import Turnstile +from python3_anticaptcha.core.serializer import GetTaskResultResponseSer + + +class TestTurnstile(BaseTest): + websiteURL = "https://demo.turnstile.workers.dev/" + websiteKey = "1x00000000000000000000AA" + + def test_sio_success(self): + instance = Turnstile( + api_key=self.API_KEY, + websiteKey=self.websiteKey, + websiteURL=self.websiteURL, + captcha_type=CaptchaTypeEnm.TurnstileTaskProxyless, + ) + result = instance.captcha_handler() + + assert isinstance(result, dict) + ser_result = GetTaskResultResponseSer(**result) + assert ser_result.errorId == 0 + assert ser_result.taskId is not None + assert ser_result.cost != 0.0 + + async def test_aio_success(self): + instance = Turnstile( + api_key=self.API_KEY, + websiteKey=self.websiteKey, + websiteURL=self.websiteURL, + captcha_type=CaptchaTypeEnm.TurnstileTaskProxyless, + ) + result = await instance.aio_captcha_handler() + + assert isinstance(result, dict) + ser_result = GetTaskResultResponseSer(**result) + assert ser_result.errorId == 0 + assert ser_result.taskId is not None + assert ser_result.cost != 0.0 + + def test_err_captcha_type(self): + with pytest.raises(ValueError): + Turnstile( + api_key=self.API_KEY, + websiteKey=self.websiteKey, + websiteURL=self.websiteURL, + captcha_type=self.get_random_string(length=10), + ) + + @pytest.mark.parametrize("proxyType", ProxyTypeEnm) + def test_proxy_args(self, proxyType: ProxyTypeEnm): + proxy_args = self.get_proxy_args() + proxy_args.update({"proxyType": proxyType}) + instance = Turnstile( + api_key=self.API_KEY, + websiteKey=self.websiteKey, + websiteURL=self.websiteURL, + captcha_type=CaptchaTypeEnm.TurnstileTask, + **proxy_args, + ) + for key, value in proxy_args.items(): + assert instance.task_params[key] == value