Skip to content

Commit 8bfe1ac

Browse files
author
Andrei
authored
Merge pull request #41 from AndreiDrang/main
0.9.1
2 parents f35454d + ad39752 commit 8bfe1ac

8 files changed

Lines changed: 59 additions & 51 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9"
1+
__version__ = "0.9.1"

src/python3_capsolver/core/serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ class ReCaptchaV3Ser(WebsiteDataOptionsSer):
8080
)
8181

8282

83-
class HCaptchaClassificationOptionsSer(BaseModel):
83+
class HCaptchaClassificationOptionsSer(TaskSer):
8484
queries: List[str] = Field(..., description="Base64-encoded images, do not include 'data:image/***;base64,'")
8585
question: str = Field(
8686
..., description="Question ID. Support English and Chinese, other languages please convert yourself"
8787
)
8888

8989

90-
class FunCaptchaClassificationOptionsSer(BaseModel):
90+
class FunCaptchaClassificationOptionsSer(TaskSer):
9191
images: List[str] = Field(..., description="Base64-encoded images, do not include 'data:image/***;base64,'")
9292
question: str = Field(
9393
...,

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BaseTest:
2727
proxyPort = 9999
2828

2929
@staticmethod
30-
def get_random_string(length: int) -> str:
30+
def get_random_string(length: int = 36) -> str:
3131
"""
3232
Method generate random string with set length
3333

tests/test_datadome_slider.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ def test_captcha_handler_exist(self):
1616
def test_aio_captcha_handler_exist(self):
1717
assert "aio_captcha_handler" in DatadomeSlider.__dict__.keys()
1818

19+
def test_wrong_captcha_type(self):
20+
with pytest.raises(ValueError):
21+
DatadomeSlider(
22+
api_key=self.API_KEY,
23+
captcha_type=self.get_random_string(36),
24+
websiteURL=websiteURL,
25+
captchaUrl=captchaUrl,
26+
userAgent=self.get_random_string(36),
27+
)
28+
1929

2030
class TestDatadomeSlider(BaseTest):
2131
"""

tests/test_hcaptcha.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from tests.conftest import BaseTest
66
from python3_capsolver.hcaptcha import HCaptcha, HCaptchaClassification
77
from python3_capsolver.core.enum import HCaptchaTypeEnm, HCaptchaClassificationTypeEnm
8+
from python3_capsolver.core.serializer import CaptchaResponseSer
89

910
HCAPTCHA_KEY = "3ceb8624-1970-4e6b-91d5-70317b70b651"
1011
PAGE_URL = "https://accounts.hcaptcha.com/demo"
@@ -243,6 +244,15 @@ async def test_aio_params_context(self):
243244
Failed tests
244245
"""
245246

247+
def test_wrong_captcha_type(self):
248+
with pytest.raises(ValueError):
249+
HCaptchaClassification(
250+
api_key=self.API_KEY,
251+
captcha_type=self.get_random_string(),
252+
queries=[self.image_body],
253+
question=self.question,
254+
)
255+
246256
def test_no_queries(self):
247257
with pytest.raises(TypeError):
248258
HCaptchaClassification(
@@ -259,27 +269,26 @@ def test_no_question(self):
259269
queries=[self.image_body],
260270
)
261271

262-
263-
"""
264-
async def test_aio_api_key_err(self):
265-
result = await HCaptchaClassification(
272+
def test_api_key_err(self):
273+
result = HCaptchaClassification(
266274
api_key=self.get_random_string(36),
267275
captcha_type=self.captcha_type,
268276
queries=[self.image_body],
269277
question=self.question,
270-
).aio_captcha_handler()
278+
).captcha_handler()
279+
assert isinstance(result, CaptchaResponseSer)
271280
assert result.errorId == 1
272281
assert result.errorCode == "ERROR_KEY_DENIED_ACCESS"
273282
assert not result.solution
274283

275-
def test_api_key_err(self):
276-
result = HCaptchaClassification(
284+
async def test_aio_api_key_err(self):
285+
result = await HCaptchaClassification(
277286
api_key=self.get_random_string(36),
278287
captcha_type=self.captcha_type,
279288
queries=[self.image_body],
280289
question=self.question,
281-
).captcha_handler()
290+
).aio_captcha_handler()
291+
assert isinstance(result, CaptchaResponseSer)
282292
assert result.errorId == 1
283293
assert result.errorCode == "ERROR_KEY_DENIED_ACCESS"
284294
assert not result.solution
285-
"""

tests/test_image_to_text.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import base64
22

3+
import pytest
4+
35
from tests.conftest import BaseTest
46
from python3_capsolver.core.enum import ResponseStatusEnm
57
from python3_capsolver.image_to_text import ImageToText
@@ -9,18 +11,24 @@
911
img_data = img_file.read()
1012

1113

12-
class TestImageToText(BaseTest):
13-
image_body = base64.b64encode(img_data).decode("utf-8")
14-
"""
15-
Success tests
16-
"""
17-
14+
class TestImageToTextBase(BaseTest):
1815
def test_captcha_handler_exist(self):
1916
assert "captcha_handler" in ImageToText.__dict__.keys()
2017

2118
def test_aio_captcha_handler_exist(self):
2219
assert "aio_captcha_handler" in ImageToText.__dict__.keys()
2320

21+
def test_wrong_captcha_type(self):
22+
with pytest.raises(ValueError):
23+
ImageToText(api_key=self.API_KEY, captcha_type=self.get_random_string())
24+
25+
26+
class TestImageToText(BaseTest):
27+
image_body = base64.b64encode(img_data).decode("utf-8")
28+
"""
29+
Success tests
30+
"""
31+
2432
def test_solve_image(self):
2533
resp = ImageToText(api_key=self.API_KEY).captcha_handler(body=self.image_body)
2634
assert isinstance(resp, CaptchaResponseSer)

tests/test_mt_captcha.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ def test_captcha_handler_exist(self):
1919
def test_aio_captcha_handler_exist(self):
2020
assert "aio_captcha_handler" in MtCaptcha.__dict__.keys()
2121

22+
def test_wrong_captcha_type(self):
23+
with pytest.raises(ValueError):
24+
MtCaptcha(
25+
api_key=self.API_KEY,
26+
captcha_type=self.get_random_string(),
27+
websiteKey=websiteKey,
28+
proxy=proxy,
29+
websiteURL=websiteURL,
30+
)
31+
2232
@pytest.mark.parametrize("captcha_type", captcha_types)
2333
def test_no_website_url(self, captcha_type: str):
2434
with pytest.raises(TypeError):

tests/test_recaptcha.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,11 @@ def test_solve(self, captcha_type: str):
7070
assert resp.errorDescription is None
7171
assert resp.solution is not None
7272

73-
"""def test_solve_context(self):
74-
with ReCaptcha(
75-
api_key=self.API_KEY,
76-
captcha_type=self.captcha_type,
77-
websiteURL=self.pageurl,
78-
websiteKey=self.googlekey,
79-
) as instance:
80-
resp = instance.captcha_handler()
81-
assert isinstance(resp, CaptchaResponseSer)
82-
assert resp.status == ResponseStatusEnm.Ready
83-
assert resp.errorId == 0
84-
assert resp.errorCode is None
85-
assert resp.errorDescription is None
86-
assert resp.solution is not None
87-
88-
async def test_aio_solve(self):
73+
@pytest.mark.parametrize("captcha_type", captcha_types)
74+
async def test_aio_solve(self, captcha_type: str):
8975
resp = await ReCaptcha(
9076
api_key=self.API_KEY,
91-
captcha_type=self.captcha_type,
77+
captcha_type=captcha_type,
9278
websiteURL=self.pageurl,
9379
websiteKey=self.googlekey,
9480
).aio_captcha_handler()
@@ -99,21 +85,6 @@ async def test_aio_solve(self):
9985
assert resp.errorDescription is None
10086
assert resp.solution is not None
10187

102-
async def test_aio_solve_context(self):
103-
with ReCaptcha(
104-
api_key=self.API_KEY,
105-
captcha_type=self.captcha_type,
106-
websiteURL=self.pageurl,
107-
websiteKey=self.googlekey,
108-
) as instance:
109-
resp = await instance.aio_captcha_handler()
110-
assert isinstance(resp, CaptchaResponseSer)
111-
assert resp.status == ResponseStatusEnm.Ready
112-
assert resp.errorId == 0
113-
assert resp.errorCode is None
114-
assert resp.errorDescription is None
115-
assert resp.solution is not None"""
116-
11788
"""
11889
Failed tests
11990
"""

0 commit comments

Comments
 (0)