Skip to content

Commit

Permalink
Update test_rotate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Dec 7, 2023
1 parent f659412 commit 0a8b885
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions tests/test_rotate.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
import pytest

from tests.conftest import BaseTest
from python_rucaptcha.core.enums import RotateCaptchaEnm
from python_rucaptcha.rotate_captcha import RotateCaptcha
from python_rucaptcha.core.serializer import GetTaskResultResponseSer


class TestRotateCaptcha(BaseTest):
captcha_file = "src/examples/rotate/rotate_ex.png"
captcha_url = "https://rucaptcha.com/dist/web/b771cc7c5eb0c1a811fcb91d54e4443a.png"

"""
Success tests
"""
kwargs_params = {
"angle": 45,
"comment": "comment comm entcomm entcomment",
}

def test_methods_exists(self):
assert "captcha_handler" in RotateCaptcha.__dict__.keys()
assert "aio_captcha_handler" in RotateCaptcha.__dict__.keys()

def test_args(self):
instance = RotateCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.create_task_payload["clientKey"] == self.RUCAPTCHA_KEY
assert instance.create_task_payload["task"]["type"] == RotateCaptchaEnm.RotateTask

def test_kwargs(self):
instance = RotateCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY,
**self.kwargs_params,
)
assert set(self.kwargs_params.keys()).issubset(set(instance.create_task_payload["task"].keys()))
assert set(self.kwargs_params.values()).issubset(set(instance.create_task_payload["task"].values()))

"""
Success tests
"""

def test_basic_data_link(self):
instance = RotateCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)

result = instance.captcha_handler(captcha_link=self.captcha_url)

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand All @@ -40,14 +57,13 @@ def test_basic_data_file(self):
result = instance.captcha_handler(captcha_file=self.captcha_file)

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand All @@ -58,14 +74,13 @@ def test_basic_data_base64(self):
result = instance.captcha_handler(captcha_base64=f.read())

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand All @@ -76,14 +91,13 @@ async def test_aio_basic_data_link(self):
result = await instance.aio_captcha_handler(captcha_link=self.captcha_url)

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand All @@ -94,14 +108,13 @@ async def test_aio_basic_data_file(self):
result = await instance.aio_captcha_handler(captcha_file=self.captcha_file)

assert isinstance(result, dict) is True
if result["error"] is False:
assert result["error"] is False
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand All @@ -113,14 +126,13 @@ async def test_aio_basic_data_base64(self):
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
if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["rotate"], int) is True
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["errorId"] in (1, 12)
assert result["errorCode"] == "ERROR_CAPTCHA_UNSOLVABLE"

assert result.keys() == GetTaskResultResponseSer().to_dict().keys()

Expand Down

0 comments on commit 0a8b885

Please sign in to comment.