2022-12-13 22:11:38 +00:00
|
|
|
from tenacity import AsyncRetrying
|
|
|
|
from urllib3.util.retry import Retry
|
|
|
|
|
2023-03-20 00:58:52 +00:00
|
|
|
from tests.conftest import BaseTest
|
2022-12-13 22:16:52 +00:00
|
|
|
from python3_anticaptcha.core.base import BaseCaptcha
|
2024-10-05 20:17:28 +00:00
|
|
|
from python3_anticaptcha.core.enum import MyEnum
|
|
|
|
from python3_anticaptcha.core.config import RETRIES, ASYNC_RETRIES, attempts_generator
|
2022-12-13 22:11:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCore(BaseTest):
|
|
|
|
"""
|
|
|
|
Success tests
|
|
|
|
"""
|
|
|
|
|
2024-10-05 20:17:28 +00:00
|
|
|
def test_retries(self):
|
2022-12-13 22:11:38 +00:00
|
|
|
assert isinstance(RETRIES, Retry)
|
|
|
|
|
|
|
|
def test_async_reties(self):
|
|
|
|
assert isinstance(ASYNC_RETRIES, AsyncRetrying)
|
|
|
|
|
|
|
|
def test_create_base(self):
|
|
|
|
BaseCaptcha(
|
2022-12-13 22:16:52 +00:00
|
|
|
api_key=self.get_random_string(32),
|
2022-12-13 22:11:38 +00:00
|
|
|
sleep_time=self.sleep_time,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_aio_create_base(self):
|
|
|
|
BaseCaptcha(
|
2022-12-13 22:16:52 +00:00
|
|
|
api_key=self.get_random_string(32),
|
2022-12-13 22:11:38 +00:00
|
|
|
sleep_time=self.sleep_time,
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_create_base_context(self):
|
|
|
|
with BaseCaptcha(
|
2022-12-13 22:16:52 +00:00
|
|
|
api_key=self.get_random_string(32),
|
2022-12-13 22:11:38 +00:00
|
|
|
sleep_time=self.sleep_time,
|
|
|
|
) as instance:
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def test_aio_create_base_context(self):
|
|
|
|
async with BaseCaptcha(
|
2022-12-13 22:16:52 +00:00
|
|
|
api_key=self.get_random_string(32),
|
2022-12-13 22:11:38 +00:00
|
|
|
sleep_time=self.sleep_time,
|
|
|
|
) as instance:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class TestConfig(BaseTest):
|
|
|
|
def test_attempts_generator(self):
|
|
|
|
attempt = None
|
|
|
|
attempts = attempts_generator(amount=5)
|
|
|
|
for attempt in attempts:
|
|
|
|
assert isinstance(attempt, int)
|
|
|
|
assert attempt == 4
|
2023-03-20 01:07:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestEnum(BaseTest):
|
|
|
|
def test_enum_list(self):
|
|
|
|
assert isinstance(MyEnum.list(), list)
|
|
|
|
|
|
|
|
def test_enum_list_values(self):
|
|
|
|
assert isinstance(MyEnum.list_values(), list)
|
|
|
|
|
|
|
|
def test_enum_list_names(self):
|
|
|
|
assert isinstance(MyEnum.list_names(), list)
|