Skip to content

Commit

Permalink
Merge pull request #154 from AndreiDrang/master
Browse files Browse the repository at this point in the history
5.3.1
  • Loading branch information
AndreiDrang authored Apr 4, 2023
2 parents 76e91a5 + 493e3cb commit ed7550c
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
paths:
- '.github/workflows/test.yml'
- 'src/**'
- 'tests/**'
- 'Makefile'
- 'requirements.test.txt'
pull_request:
branches: [ "master", "release"]
paths:
- '.github/workflows/test.yml'
- 'src/**'
- 'tests/**'
- 'Makefile'
- 'requirements.test.txt'
schedule:
Expand Down
2 changes: 1 addition & 1 deletion src/python_rucaptcha/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.3"
__version__ = "5.3.1"
22 changes: 22 additions & 0 deletions src/python_rucaptcha/audio_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def __init__(
'errorBody': None
}
>>> with open("src/examples/mediacaptcha_audio/recaptcha_55914.mp3", "rb") as f:
... file_data = f.read()
>>> AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).captcha_handler(captcha_base64=file_data)
{
'captchaSolve': 'five five nine one four',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
>>> await AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... lang='en'
... ).aio_captcha_handler(captcha_file='examples/mediacaptcha_audio/recaptcha_55914.mp3')
Expand All @@ -48,6 +59,17 @@ def __init__(
'errorBody': None
}
>>> with open("src/examples/mediacaptcha_audio/recaptcha_55914.mp3", "rb") as f:
... file_data = f.read()
>>> await AudioCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).aio_captcha_handler(captcha_base64=file_data)
{
'captchaSolve': 'five five nine one four',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
Returns:
Dict with full server response
Expand Down
21 changes: 21 additions & 0 deletions src/python_rucaptcha/image_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def __init__(
'errorBody': None
}
>>> with open("src/examples/088636.png", "rb") as f:
... file_data = f.read()
>>> ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).captcha_handler(captcha_base64=file_data)
{
'captchaSolve': 'W9H5K',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
>>> await ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... ).aio_captcha_handler(captcha_link="https://rucaptcha.com/dist/web/99581b9d446a509a0a01954438a5e36a.jpg")
{
Expand Down Expand Up @@ -84,6 +95,16 @@ def __init__(
'errorBody': None
}
>>> with open("src/examples/088636.png", "rb") as f:
... file_data = f.read()
>>> await ImageCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).aio_captcha_handler(captcha_base64=file_data)
{
'captchaSolve': 'W9H5K',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
Returns:
Dict with full server response
Expand Down
23 changes: 23 additions & 0 deletions src/python_rucaptcha/rotate_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def __init__(self, method: str = RotateCaptchaEnm.ROTATECAPTCHA.value, *args, **
'errorBody': None
}
>>> with open("src/examples/rotate/rotate_ex.png", "rb") as f:
... file_data = f.read()
>>> RotateCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).captcha_handler(captcha_base64=file_data)
{
'captchaSolve': '160',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
>>> await RotateCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122",
... ).aio_captcha_handler(captcha_file="examples/rotate/rotate_ex.png")
{
Expand All @@ -47,6 +58,18 @@ def __init__(self, method: str = RotateCaptchaEnm.ROTATECAPTCHA.value, *args, **
'errorBody': None
}
>>> with open("src/examples/rotate/rotate_ex.png", "rb") as f:
... file_data = f.read()
>>> await RotateCaptcha(rucaptcha_key="aa9011f31111181111168611f1151122"
... ).aio_captcha_handler(captcha_base64=file_data)
{
'captchaSolve': '160',
'taskId': 73243152973,
'error': False,
'errorBody': None
}
Returns:
Dict with full server response
Expand Down
70 changes: 66 additions & 4 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ def test_basic_data_link(self, save_format):

assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
def test_basic_data_base64(self, save_format):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format)

assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY

with open(self.captcha_file, "rb") as f:
result = instance.captcha_handler(captcha_base64=f.read())

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
assert isinstance(result["taskId"], int) is True
assert result["errorBody"] is None
assert isinstance(result["captchaSolve"], str) is True
else:
assert result["error"] is True
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
async def test_aio_basic_data_file(self, save_format):
Expand Down Expand Up @@ -100,6 +121,28 @@ async def test_aio_basic_data_link(self, save_format):

assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
async def test_aio_basic_data_base64(self, save_format):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format)

assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY

with open(self.captcha_file, "rb") as f:
result = await instance.aio_captcha_handler(captcha_base64=f.read())

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
assert isinstance(result["taskId"], int) is True
assert result["errorBody"] is None
assert isinstance(result["captchaSolve"], str) is True
else:
assert result["error"] is True
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == ResponseSer().dict().keys()

"""
Fail tests
"""
Expand Down Expand Up @@ -134,10 +177,6 @@ async def test_aio_no_captcha(self):
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

"""
Failed tests
"""

def test_wrong_link(self):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)

Expand Down Expand Up @@ -165,6 +204,16 @@ def test_wrong_path(self):
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

def test_wrong_base64(self):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
async def test_aio_wrong_link(self):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
Expand Down Expand Up @@ -193,3 +242,16 @@ async def test_aio_wrong_path(self):
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
async def test_aio_wrong_base64(self):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = await instance.aio_captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()
63 changes: 63 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ def test_basic_data_file(self, save_format):
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
def test_basic_data_base64(self, save_format):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format)

assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY

with open(self.captcha_file, "rb") as f:
result = instance.captcha_handler(captcha_base64=f.read())

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
assert isinstance(result["taskId"], int) is True
assert result["errorBody"] is None
assert isinstance(result["captchaSolve"], str) is True
else:
assert result["error"] is True
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
async def test_aio_basic_data_link(self, save_format):
Expand Down Expand Up @@ -86,6 +106,26 @@ async def test_aio_basic_data_file(self, save_format):
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
async def test_aio_basic_data_base64(self, save_format):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format)

assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY

with open(self.captcha_file, "rb") as f:
result = await instance.aio_captcha_handler(captcha_base64=f.read())
assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
assert isinstance(result["taskId"], int) is True
assert result["errorBody"] is None
assert isinstance(result["captchaSolve"], str) is True
else:
assert result["error"] is True
assert result["errorBody"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == ResponseSer().dict().keys()

"""
Fail tests
"""
Expand Down Expand Up @@ -123,6 +163,16 @@ def test_wrong_link(self):
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

def test_wrong_base64(self):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
async def test_aio_wrong_link(self):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
Expand All @@ -134,6 +184,19 @@ async def test_aio_wrong_link(self):
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()

@pytest.mark.asyncio
async def test_aio_wrong_base64(self):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = await instance.aio_captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == ResponseSer().dict().keys()


class TestDeathByImageCaptcha(BaseImageCaptcha, DeathByTest):
"""
Expand Down
Loading

0 comments on commit ed7550c

Please sign in to comment.