Skip to content

Commit

Permalink
Update test_image_to_text.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiDrang committed Jan 18, 2025
1 parent 52d1901 commit 9564862
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tests/test_image_to_text.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import base64

from tests.conftest import BaseTest
from python3_capsolver.core.enum import ResponseStatusEnm
from python3_capsolver.image_to_text import ImageToText
from python3_capsolver.core.serializer import CaptchaResponseSer

with open("tests/files/captcha_example.jpeg", "rb") as img_file:
img_data = img_file.read()


class TestImageToTextBase(BaseTest):
def test_captcha_handler_exist(self):
Expand All @@ -16,13 +11,12 @@ def test_captcha_handler_exist(self):


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(task_payload=dict(body=self.image_body))
resp = ImageToText(api_key=self.API_KEY).captcha_handler(task_payload=dict(body=self.read_image_as_str()))
assert isinstance(resp, dict)
assert CaptchaResponseSer(**resp)
assert resp["status"] == ResponseStatusEnm.Ready.value
Expand All @@ -32,7 +26,9 @@ def test_solve_image(self):
assert isinstance(resp["solution"], dict)

async def test_aio_solve_image(self):
resp = await ImageToText(api_key=self.API_KEY).aio_captcha_handler(task_payload=dict(body=self.image_body))
resp = await ImageToText(api_key=self.API_KEY).aio_captcha_handler(
task_payload=dict(body=self.read_image_as_str())
)
assert isinstance(resp, dict)
assert CaptchaResponseSer(**resp)
assert resp["status"] == ResponseStatusEnm.Ready.value
Expand All @@ -47,15 +43,15 @@ async def test_aio_solve_image(self):

def test_captcha_handler_api_key_err(self):
result = ImageToText(api_key=self.get_random_string(36)).captcha_handler(
task_payload=dict(body=self.image_body)
task_payload=dict(body=self.read_image_as_str())
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
assert result["solution"] is None

async def test_aio_captcha_handler_api_key_err(self):
result = await ImageToText(api_key=self.get_random_string(36)).aio_captcha_handler(
task_payload=dict(body=self.image_body)
task_payload=dict(body=self.read_image_as_str())
)
assert result["errorId"] == 1
assert result["errorCode"] == "ERROR_KEY_DENIED_ACCESS"
Expand Down

0 comments on commit 9564862

Please sign in to comment.