2022-12-13 22:11:38 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-12-15 20:04:10 +00:00
|
|
|
from python3_anticaptcha.core.enum import ProxyTypeEnm
|
|
|
|
|
2022-12-13 22:11:38 +00:00
|
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
2023-03-20 00:58:52 +00:00
|
|
|
def delay_func():
|
2024-12-14 23:41:56 +00:00
|
|
|
time.sleep(0.3)
|
2022-12-13 22:11:38 +00:00
|
|
|
|
|
|
|
|
2023-03-20 00:58:52 +00:00
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def delay_class():
|
2024-12-15 20:20:11 +00:00
|
|
|
time.sleep(1)
|
2023-03-20 00:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures("delay_func")
|
|
|
|
@pytest.mark.usefixtures("delay_class")
|
2022-12-13 22:11:38 +00:00
|
|
|
class BaseTest:
|
2022-12-13 22:16:52 +00:00
|
|
|
API_KEY = os.getenv("API_KEY", "ad9053f3182ca81755768608fa75")
|
2022-12-13 22:11:38 +00:00
|
|
|
sleep_time = 5
|
|
|
|
|
|
|
|
proxyAddress = "0.0.0.0"
|
|
|
|
proxyPort = 9999
|
|
|
|
|
2024-12-15 20:04:10 +00:00
|
|
|
def get_proxy_args(self) -> dict:
|
|
|
|
return {
|
|
|
|
"proxyType": ProxyTypeEnm.http,
|
|
|
|
"proxyAddress": "0.0.0.0",
|
|
|
|
"proxyPort": 445,
|
|
|
|
"proxyLogin": self.get_random_string(),
|
|
|
|
"proxyPassword": self.get_random_string(),
|
|
|
|
}
|
|
|
|
|
2022-12-13 22:11:38 +00:00
|
|
|
@staticmethod
|
2024-12-15 20:04:10 +00:00
|
|
|
def get_random_string(length: int = 10) -> str:
|
2022-12-13 22:11:38 +00:00
|
|
|
"""
|
|
|
|
Method generate random string with set length
|
|
|
|
|
|
|
|
Args:
|
|
|
|
length: Len of generated string
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Random letter string
|
|
|
|
"""
|
|
|
|
# choose from all lowercase letter
|
|
|
|
letters = string.ascii_lowercase
|
|
|
|
result_str = "".join(random.choice(letters) for _ in range(length))
|
|
|
|
return result_str
|
2024-12-14 23:08:49 +00:00
|
|
|
|
|
|
|
def read_file(self, file_path: str) -> bytes:
|
|
|
|
with open(file_path, "rb") as file:
|
|
|
|
return file.read()
|