-
Notifications
You must be signed in to change notification settings - Fork 18
/
acceptance_tests.py
101 lines (85 loc) · 2.97 KB
/
acceptance_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Acceptance tests
"""
import asyncio
import logging
import os
from importlib import import_module
from unicaps import CaptchaSolver, AsyncCaptchaSolver
from unicaps.__version__ import __version__
logging.basicConfig(level=logging.INFO)
SERVICES = {
'2captcha.com': 'API_KEY_2CAPTCHA',
'anti-captcha.com': 'API_KEY_ANTICAPTCHA',
'azcaptcha.com': 'API_KEY_AZCAPTCHA',
'captcha.guru': 'API_KEY_CAPTCHA_GURU',
'cptch.net': 'API_KEY_CPTCH_NET',
'deathbycaptcha.com': 'API_KEY_DEATHBYCAPTCHA'
}
EXAMPLES = [
'image',
'recaptcha_v2',
'recaptcha_v2_invisible',
'recaptcha_v2_enterprise',
'recaptcha_v3',
'hcaptcha',
'keycaptcha',
'geetest',
'geetest_v4',
'capy_puzzle',
'text',
'funcaptcha'
]
def main():
for service_name, env_var_name in SERVICES.items():
api_key = os.getenv(env_var_name)
if not api_key:
logging.error(
'Unable to read API key for the "%s" service. '
'The environment variable "%s" doesn\'t exist!',
service_name,
env_var_name
)
continue
logging.info('######### Service: %s #########', service_name)
with CaptchaSolver(service_name, api_key) as solver:
status = solver.get_status()
balance = solver.get_balance()
logging.info('Status: %s. Balance: %.2f', 'OK' if status else 'ERROR', balance)
for example_name in EXAMPLES:
logging.info('Current module: %s', example_name)
module = import_module(f'examples.{example_name}')
try:
module.run(solver)
except Exception:
logging.exception('%s run exception', module)
async def async_main():
for service_name, env_var_name in SERVICES.items():
api_key = os.getenv(env_var_name)
if not api_key:
logging.error(
'Unable to read API key for the "%s" service. '
'The environment variable "%s" doesn\'t exist!',
service_name,
env_var_name
)
continue
logging.info('######### Service: %s #########', service_name)
async with AsyncCaptchaSolver(service_name, api_key) as async_solver:
status = await async_solver.get_status()
balance = await async_solver.get_balance()
logging.info(
'Status: %s. Balance: %.2f',
'OK' if status else 'ERROR',
balance
)
for example_name in EXAMPLES:
logging.info('Current module: %s', example_name)
module = import_module(f'examples.async_{example_name}')
try:
await module.run(async_solver)
except Exception:
logging.exception('%s run exception', module)
if __name__ == '__main__':
main()
asyncio.run(async_main(), debug=False)