Skip to content

Commit 991e41a

Browse files
committed
upd tests
1 parent 07e3a52 commit 991e41a

6 files changed

Lines changed: 133 additions & 11 deletions

File tree

tests/test_cloudflare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import pytest
22

33
from tests.conftest import BaseTest
4-
from python3_capsolver.cloudflare import Cloudflare
54
from python3_capsolver.core.enum import CaptchaTypeEnm
5+
from python3_capsolver.cloudflare import Cloudflare
66

77

88
class TestCloudflare(BaseTest):

tests/test_core.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ def test_async_retries(self):
2323
def test_create_base(self):
2424
CaptchaParams(
2525
api_key=self.get_random_string(36),
26-
captcha_type=CaptchaTypeEnm.VisionEngine,
26+
captcha_type=CaptchaTypeEnm.Control,
2727
request_url=REQUEST_URL,
2828
sleep_time=self.sleep_time,
2929
)
3030

3131
def test_aio_create_base(self):
3232
CaptchaParams(
3333
api_key=self.get_random_string(36),
34-
captcha_type=CaptchaTypeEnm.VisionEngine,
34+
captcha_type=CaptchaTypeEnm.Control,
3535
request_url=REQUEST_URL,
3636
sleep_time=self.sleep_time,
3737
)
3838

3939
def test_create_base_context(self):
4040
with CaptchaParams(
4141
api_key=self.get_random_string(36),
42-
captcha_type=CaptchaTypeEnm.VisionEngine,
42+
captcha_type=CaptchaTypeEnm.Control,
4343
request_url=REQUEST_URL,
4444
sleep_time=self.sleep_time,
4545
) as instance:
@@ -48,7 +48,7 @@ def test_create_base_context(self):
4848
async def test_aio_create_base_context(self):
4949
async with CaptchaParams(
5050
api_key=self.get_random_string(36),
51-
captcha_type=CaptchaTypeEnm.VisionEngine,
51+
captcha_type=CaptchaTypeEnm.Control,
5252
request_url=REQUEST_URL,
5353
sleep_time=self.sleep_time,
5454
) as instance:
@@ -60,27 +60,27 @@ async def test_aio_create_base_context(self):
6060

6161
def test_no_key_err(self):
6262
with pytest.raises(TypeError):
63-
CaptchaParams(captcha_type=CaptchaTypeEnm.VisionEngine, request_url=REQUEST_URL, sleep_time=self.sleep_time)
63+
CaptchaParams(captcha_type=CaptchaTypeEnm.Control, request_url=REQUEST_URL, sleep_time=self.sleep_time)
6464

6565
def test_no_key_err_context(self):
6666
with pytest.raises(TypeError):
6767
with CaptchaParams(
68-
captcha_type=CaptchaTypeEnm.VisionEngine, request_url=REQUEST_URL, sleep_time=self.sleep_time
68+
captcha_type=CaptchaTypeEnm.Control, request_url=REQUEST_URL, sleep_time=self.sleep_time
6969
) as instance:
7070
pass
7171

7272
async def test_aio_no_key_err_context(self):
7373
with pytest.raises(TypeError):
7474
async with CaptchaParams(
75-
captcha_type=CaptchaTypeEnm.VisionEngine, request_url=REQUEST_URL, sleep_time=self.sleep_time
75+
captcha_type=CaptchaTypeEnm.Control, request_url=REQUEST_URL, sleep_time=self.sleep_time
7676
) as instance:
7777
pass
7878

7979
def test_create_base_err_context(self):
8080
with pytest.raises(Exception):
8181
with CaptchaParams(
8282
api_key=self.get_random_string(36),
83-
captcha_type=CaptchaTypeEnm.VisionEngine,
83+
captcha_type=CaptchaTypeEnm.Control,
8484
request_url=REQUEST_URL,
8585
sleep_time=self.sleep_time,
8686
) as instance:
@@ -90,14 +90,14 @@ async def test_aio_create_base_err_context(self):
9090
with pytest.raises(Exception):
9191
async with CaptchaParams(
9292
api_key=self.get_random_string(36),
93-
captcha_type=CaptchaTypeEnm.VisionEngine,
93+
captcha_type=CaptchaTypeEnm.Control,
9494
request_url=REQUEST_URL,
9595
sleep_time=self.sleep_time,
9696
) as instance:
9797
raise Exception()
9898

9999

100-
class TestEnum(BaseTest):
100+
class TestMyEnum(BaseTest):
101101
def test_enum_list(self):
102102
assert isinstance(MyEnum.list(), list)
103103

tests/test_datadome.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
from tests.conftest import BaseTest
4+
from python3_capsolver.core.enum import CaptchaTypeEnm
5+
from python3_capsolver.datadome_slider import DatadomeSlider
6+
7+
8+
class TestDatadomeSliderBase(BaseTest):
9+
captcha_types = (CaptchaTypeEnm.DatadomeSliderTask,)
10+
11+
@pytest.mark.parametrize("captcha_type", captcha_types)
12+
def test_captcha_handler_exist(self, captcha_type):
13+
instance = DatadomeSlider(api_key=self.get_random_string(36), captcha_type=captcha_type)
14+
assert "captcha_handler" in instance.__dir__()
15+
assert "aio_captcha_handler" in instance.__dir__()
16+
17+
@pytest.mark.parametrize("captcha_type", captcha_types)
18+
def test_api_key_err(self, captcha_type):
19+
result = DatadomeSlider(api_key=self.get_random_string(36), captcha_type=captcha_type).captcha_handler(
20+
task_payload={"some": "data"}
21+
)
22+
assert result["errorId"] == 1
23+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
24+
assert result["solution"] is None
25+
26+
@pytest.mark.parametrize("captcha_type", captcha_types)
27+
async def test_aio_api_key_err(self, captcha_type):
28+
result = await DatadomeSlider(
29+
api_key=self.get_random_string(36), captcha_type=captcha_type
30+
).aio_captcha_handler(task_payload={"some": "data"})
31+
assert result["errorId"] == 1
32+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
33+
assert result["solution"] is None

tests/test_friendly.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
from tests.conftest import BaseTest
4+
from python3_capsolver.core.enum import CaptchaTypeEnm
5+
from python3_capsolver.friendly_captcha import FriendlyCaptcha
6+
7+
8+
class TestFriendlyCaptchaBase(BaseTest):
9+
captcha_types = (CaptchaTypeEnm.FriendlyCaptchaTaskProxyless,)
10+
11+
@pytest.mark.parametrize("captcha_type", captcha_types)
12+
def test_captcha_handler_exist(self, captcha_type):
13+
instance = FriendlyCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type)
14+
assert "captcha_handler" in instance.__dir__()
15+
assert "aio_captcha_handler" in instance.__dir__()
16+
17+
@pytest.mark.parametrize("captcha_type", captcha_types)
18+
def test_api_key_err(self, captcha_type):
19+
result = FriendlyCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type).captcha_handler(
20+
task_payload={"some": "data"}
21+
)
22+
assert result["errorId"] == 1
23+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
24+
assert result["solution"] is None
25+
26+
@pytest.mark.parametrize("captcha_type", captcha_types)
27+
async def test_aio_api_key_err(self, captcha_type):
28+
result = await FriendlyCaptcha(
29+
api_key=self.get_random_string(36), captcha_type=captcha_type
30+
).aio_captcha_handler(task_payload={"some": "data"})
31+
assert result["errorId"] == 1
32+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
33+
assert result["solution"] is None

tests/test_vision_engine.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from tests.conftest import BaseTest
2+
from python3_capsolver.vision_engine import VisionEngine
3+
4+
5+
class TestVisionEngineBase(BaseTest):
6+
def test_captcha_handler_exist(self):
7+
instance = VisionEngine(api_key=self.get_random_string(36))
8+
assert "captcha_handler" in instance.__dir__()
9+
assert "aio_captcha_handler" in instance.__dir__()
10+
11+
def test_api_key_err(self):
12+
result = VisionEngine(api_key=self.get_random_string(36)).captcha_handler(task_payload={"some": "data"})
13+
assert result["errorId"] == 1
14+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
15+
assert result["solution"] is None
16+
17+
async def test_aio_api_key_err(self):
18+
result = await VisionEngine(api_key=self.get_random_string(36)).aio_captcha_handler(
19+
task_payload={"some": "data"}
20+
)
21+
assert result["errorId"] == 1
22+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
23+
assert result["solution"] is None

tests/test_yandex.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
from tests.conftest import BaseTest
4+
from python3_capsolver.yandex import YandexCaptcha
5+
from python3_capsolver.core.enum import CaptchaTypeEnm
6+
7+
8+
class TestYandexCaptchaBase(BaseTest):
9+
captcha_types = (CaptchaTypeEnm.YandexCaptchaTaskProxyLess,)
10+
11+
@pytest.mark.parametrize("captcha_type", captcha_types)
12+
def test_captcha_handler_exist(self, captcha_type):
13+
instance = YandexCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type)
14+
assert "captcha_handler" in instance.__dir__()
15+
assert "aio_captcha_handler" in instance.__dir__()
16+
17+
@pytest.mark.parametrize("captcha_type", captcha_types)
18+
def test_api_key_err(self, captcha_type):
19+
result = YandexCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type).captcha_handler(
20+
task_payload={"some": "data"}
21+
)
22+
assert result["errorId"] == 1
23+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
24+
assert result["solution"] is None
25+
26+
@pytest.mark.parametrize("captcha_type", captcha_types)
27+
async def test_aio_api_key_err(self, captcha_type):
28+
result = await YandexCaptcha(api_key=self.get_random_string(36), captcha_type=captcha_type).aio_captcha_handler(
29+
task_payload={"some": "data"}
30+
)
31+
assert result["errorId"] == 1
32+
assert result["errorCode"] in ("ERROR_KEY_DENIED_ACCESS", "ERROR_INVALID_TASK_DATA")
33+
assert result["solution"] is None

0 commit comments

Comments
 (0)