Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.9.1 #41

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/python3_capsolver/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9"
__version__ = "0.9.1"
4 changes: 2 additions & 2 deletions src/python3_capsolver/core/serializer.py
Original file line number Diff line number Diff line change
@@ -80,14 +80,14 @@ class ReCaptchaV3Ser(WebsiteDataOptionsSer):
)


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


class FunCaptchaClassificationOptionsSer(BaseModel):
class FunCaptchaClassificationOptionsSer(TaskSer):
images: List[str] = Field(..., description="Base64-encoded images, do not include 'data:image/***;base64,'")
question: str = Field(
...,
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class BaseTest:
proxyPort = 9999

@staticmethod
def get_random_string(length: int) -> str:
def get_random_string(length: int = 36) -> str:
"""
Method generate random string with set length

10 changes: 10 additions & 0 deletions tests/test_datadome_slider.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,16 @@ def test_captcha_handler_exist(self):
def test_aio_captcha_handler_exist(self):
assert "aio_captcha_handler" in DatadomeSlider.__dict__.keys()

def test_wrong_captcha_type(self):
with pytest.raises(ValueError):
DatadomeSlider(
api_key=self.API_KEY,
captcha_type=self.get_random_string(36),
websiteURL=websiteURL,
captchaUrl=captchaUrl,
userAgent=self.get_random_string(36),
)


class TestDatadomeSlider(BaseTest):
"""
27 changes: 18 additions & 9 deletions tests/test_hcaptcha.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from tests.conftest import BaseTest
from python3_capsolver.hcaptcha import HCaptcha, HCaptchaClassification
from python3_capsolver.core.enum import HCaptchaTypeEnm, HCaptchaClassificationTypeEnm
from python3_capsolver.core.serializer import CaptchaResponseSer

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

def test_wrong_captcha_type(self):
with pytest.raises(ValueError):
HCaptchaClassification(
api_key=self.API_KEY,
captcha_type=self.get_random_string(),
queries=[self.image_body],
question=self.question,
)

def test_no_queries(self):
with pytest.raises(TypeError):
HCaptchaClassification(
@@ -259,27 +269,26 @@ def test_no_question(self):
queries=[self.image_body],
)


"""
async def test_aio_api_key_err(self):
result = await HCaptchaClassification(
def test_api_key_err(self):
result = HCaptchaClassification(
api_key=self.get_random_string(36),
captcha_type=self.captcha_type,
queries=[self.image_body],
question=self.question,
).aio_captcha_handler()
).captcha_handler()
assert isinstance(result, CaptchaResponseSer)
assert result.errorId == 1
assert result.errorCode == "ERROR_KEY_DENIED_ACCESS"
assert not result.solution

def test_api_key_err(self):
result = HCaptchaClassification(
async def test_aio_api_key_err(self):
result = await HCaptchaClassification(
api_key=self.get_random_string(36),
captcha_type=self.captcha_type,
queries=[self.image_body],
question=self.question,
).captcha_handler()
).aio_captcha_handler()
assert isinstance(result, CaptchaResponseSer)
assert result.errorId == 1
assert result.errorCode == "ERROR_KEY_DENIED_ACCESS"
assert not result.solution
"""
20 changes: 14 additions & 6 deletions tests/test_image_to_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import base64

import pytest

from tests.conftest import BaseTest
from python3_capsolver.core.enum import ResponseStatusEnm
from python3_capsolver.image_to_text import ImageToText
@@ -9,18 +11,24 @@
img_data = img_file.read()


class TestImageToText(BaseTest):
image_body = base64.b64encode(img_data).decode("utf-8")
"""
Success tests
"""

class TestImageToTextBase(BaseTest):
def test_captcha_handler_exist(self):
assert "captcha_handler" in ImageToText.__dict__.keys()

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

def test_wrong_captcha_type(self):
with pytest.raises(ValueError):
ImageToText(api_key=self.API_KEY, captcha_type=self.get_random_string())


class TestImageToText(BaseTest):
image_body = base64.b64encode(img_data).decode("utf-8")
"""
Success tests
"""

def test_solve_image(self):
resp = ImageToText(api_key=self.API_KEY).captcha_handler(body=self.image_body)
assert isinstance(resp, CaptchaResponseSer)
10 changes: 10 additions & 0 deletions tests/test_mt_captcha.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,16 @@ def test_captcha_handler_exist(self):
def test_aio_captcha_handler_exist(self):
assert "aio_captcha_handler" in MtCaptcha.__dict__.keys()

def test_wrong_captcha_type(self):
with pytest.raises(ValueError):
MtCaptcha(
api_key=self.API_KEY,
captcha_type=self.get_random_string(),
websiteKey=websiteKey,
proxy=proxy,
websiteURL=websiteURL,
)

@pytest.mark.parametrize("captcha_type", captcha_types)
def test_no_website_url(self, captcha_type: str):
with pytest.raises(TypeError):
35 changes: 3 additions & 32 deletions tests/test_recaptcha.py
Original file line number Diff line number Diff line change
@@ -70,25 +70,11 @@ def test_solve(self, captcha_type: str):
assert resp.errorDescription is None
assert resp.solution is not None

"""def test_solve_context(self):
with ReCaptcha(
api_key=self.API_KEY,
captcha_type=self.captcha_type,
websiteURL=self.pageurl,
websiteKey=self.googlekey,
) as instance:
resp = instance.captcha_handler()
assert isinstance(resp, CaptchaResponseSer)
assert resp.status == ResponseStatusEnm.Ready
assert resp.errorId == 0
assert resp.errorCode is None
assert resp.errorDescription is None
assert resp.solution is not None

async def test_aio_solve(self):
@pytest.mark.parametrize("captcha_type", captcha_types)
async def test_aio_solve(self, captcha_type: str):
resp = await ReCaptcha(
api_key=self.API_KEY,
captcha_type=self.captcha_type,
captcha_type=captcha_type,
websiteURL=self.pageurl,
websiteKey=self.googlekey,
).aio_captcha_handler()
@@ -99,21 +85,6 @@ async def test_aio_solve(self):
assert resp.errorDescription is None
assert resp.solution is not None

async def test_aio_solve_context(self):
with ReCaptcha(
api_key=self.API_KEY,
captcha_type=self.captcha_type,
websiteURL=self.pageurl,
websiteKey=self.googlekey,
) as instance:
resp = await instance.aio_captcha_handler()
assert isinstance(resp, CaptchaResponseSer)
assert resp.status == ResponseStatusEnm.Ready
assert resp.errorId == 0
assert resp.errorCode is None
assert resp.errorDescription is None
assert resp.solution is not None"""

"""
Failed tests
"""