|
| 1 | +import pytest |
| 2 | + |
| 3 | +from tests.conftest import BaseTest |
| 4 | +from python3_capsolver.cloudflare import Cloudflare |
| 5 | +from python3_capsolver.core.enum import CaptchaTypeEnm |
| 6 | + |
| 7 | + |
| 8 | +class TestCloudflare(BaseTest): |
| 9 | + captcha_types = ( |
| 10 | + CaptchaTypeEnm.AntiCloudflareTask, |
| 11 | + CaptchaTypeEnm.AntiTurnstileTaskProxyLess, |
| 12 | + ) |
| 13 | + |
| 14 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 15 | + def test_captcha_handler_exist(self, captcha_type): |
| 16 | + instance = Cloudflare(api_key=self.get_random_string(36), captcha_type=captcha_type) |
| 17 | + assert "captcha_handler" in instance.__dir__() |
| 18 | + assert "aio_captcha_handler" in instance.__dir__() |
| 19 | + |
| 20 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 21 | + def test_api_key_err(self, captcha_type): |
| 22 | + result = Cloudflare(api_key=self.get_random_string(36), captcha_type=captcha_type).captcha_handler( |
| 23 | + task_payload={"some": "data"} |
| 24 | + ) |
| 25 | + assert result["errorId"] == 1 |
| 26 | + assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA") |
| 27 | + assert result["solution"] is None |
| 28 | + |
| 29 | + @pytest.mark.parametrize("captcha_type", captcha_types) |
| 30 | + async def test_aio_api_key_err(self, captcha_type): |
| 31 | + result = await Cloudflare(api_key=self.get_random_string(36), captcha_type=captcha_type).aio_captcha_handler( |
| 32 | + task_payload={"some": "data"} |
| 33 | + ) |
| 34 | + assert result["errorId"] == 1 |
| 35 | + assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA") |
| 36 | + assert result["solution"] is None |
0 commit comments