Skip to content

Commit

Permalink
Update test_image.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Oct 3, 2023
1 parent f3ea756 commit 7c0cf3c
Showing 1 changed file with 41 additions and 50 deletions.
91 changes: 41 additions & 50 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ def test_basic_file(self, save_format):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
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"]["text"], str) 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.keys() == GetTaskResultRequestSer().dict().keys()
assert result["errorId"] == 1
assert result["status"] == "ERROR_CAPTCHA_UNSOLVABLE"

@pytest.mark.parametrize("save_format", [SaveFormatsEnm.TEMP, SaveFormatsEnm.CONST])
def test_basic_base64(self, save_format):
Expand All @@ -62,14 +61,14 @@ def test_basic_base64(self, save_format):
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"]["text"], str) 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"] == 1
assert result["status"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -79,14 +78,14 @@ async def test_aio_basic_link(self, save_format):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
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"]["text"], str) 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"] == 1
assert result["status"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -96,14 +95,14 @@ async def test_aio_basic_file(self, save_format):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
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"]["text"], str) 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"] == 1
assert result["status"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -116,14 +115,14 @@ async def test_aio_basic_base64(self, save_format):
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

if not result["errorId"]:
assert result["status"] == "ready"
assert isinstance(result["solution"]["text"], str) 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"] == 1
assert result["status"] == "ERROR_CAPTCHA_UNSOLVABLE"
assert result.keys() == GetTaskResultRequestSer().dict().keys()

"""
Expand All @@ -135,10 +134,8 @@ def test_no_captcha(self):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = instance.captcha_handler()
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["errorBody"] == ImageCaptcha.NO_CAPTCHA_ERR
assert result["captchaSolve"] == {}
assert result["errorId"] == 12
assert isinstance(result["solution"]["text"], str) is True
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -147,30 +144,26 @@ async def test_aio_no_captcha(self):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = await instance.aio_captcha_handler()
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["errorBody"] == ImageCaptcha.NO_CAPTCHA_ERR
assert result["captchaSolve"] == {}
assert result["errorId"] == 12
assert isinstance(result["solution"]["text"], str) is True
assert result.keys() == GetTaskResultRequestSer().dict().keys()

def test_wrong_link(self):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = instance.captcha_handler(captcha_link=self.get_random_string(length=50))
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result["errorId"] == 12
assert isinstance(result["solution"]["text"], str) is True
assert result.keys() == GetTaskResultRequestSer().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["errorId"] == 15
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -179,9 +172,8 @@ async def test_aio_wrong_link(self):
assert instance.params.rucaptcha_key == self.RUCAPTCHA_KEY
result = await instance.aio_captcha_handler(captcha_link=self.get_random_string(length=50))
assert isinstance(result, dict) is True
assert result["error"] is True
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result["errorId"] == 12
assert isinstance(result["solution"]["text"], str) is True
assert result.keys() == GetTaskResultRequestSer().dict().keys()

@pytest.mark.asyncio
Expand All @@ -192,13 +184,12 @@ async def test_aio_wrong_base64(self):
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["errorId"] == 15
assert result["taskId"] is None
assert result["captchaSolve"] == {}
assert result.keys() == GetTaskResultRequestSer().dict().keys()


class TestDeathByImageCaptcha(BaseImageCaptcha, DeathByTest):
class XTestDeathByImageCaptcha(BaseImageCaptcha, DeathByTest):
"""
Success tests
"""
Expand Down

0 comments on commit 7c0cf3c

Please sign in to comment.