mirror of
https://github.com/solvercaptcha/solvecaptcha-python.git
synced 2026-07-03 14:05:39 +02:00
init
This commit is contained in:
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
||||
|
||||
from solvecaptcha import Solvecaptcha
|
||||
|
||||
captcha_id = '123'
|
||||
code = 'abcd'
|
||||
|
||||
|
||||
class ApiClient():
|
||||
def in_(self, files={}, **kwargs):
|
||||
|
||||
self.incomings = kwargs
|
||||
self.incoming_files = files
|
||||
|
||||
return 'OK|' + captcha_id
|
||||
|
||||
def res(self, **kwargs):
|
||||
|
||||
return 'OK|' + code # {'code': code}
|
||||
|
||||
|
||||
class AbstractTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
self.solver = Solvecaptcha('API_KEY', pollingInterval=1)
|
||||
self.solver.api_client = ApiClient()
|
||||
|
||||
def send_return(self, for_send, method, **kwargs):
|
||||
|
||||
file = kwargs.pop('file', {})
|
||||
file = kwargs.pop('files', file)
|
||||
|
||||
result = method(file, **kwargs) if file else method(**kwargs)
|
||||
|
||||
incomings = self.solver.api_client.incomings
|
||||
for_send.update({'key': 'API_KEY'})
|
||||
for_send.update({'soft_id': 1000001})
|
||||
|
||||
files = for_send.pop('files', {})
|
||||
self.assertEqual(incomings, for_send)
|
||||
|
||||
incoming_files = self.solver.api_client.incoming_files
|
||||
incoming_files and self.assertEqual(incoming_files, files)
|
||||
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertIn('code', result)
|
||||
self.assertEqual(result['code'], code)
|
||||
|
||||
def invalid_file(self, method, **kwargs):
|
||||
|
||||
self.assertRaises(self.solver.exceptions, method, 'lost_file',
|
||||
**kwargs)
|
||||
|
||||
def too_many_files(self, method, **kwargs):
|
||||
|
||||
files = ['../examples/images/rotate.jpg'] * (self.solver.max_files + 1)
|
||||
self.assertRaises(self.solver.exceptions, method, files, **kwargs)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
file = '../examples/images/grid.jpg'
|
||||
hint_img = '../examples/images/grid_hint.jpg'
|
||||
hint_text = 'Select all images with an Orange'
|
||||
checks = {'coordinatescaptcha': 1}
|
||||
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
|
||||
file = file[3:]
|
||||
hint_img = hint_img[3:]
|
||||
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CoordinatesTest(AbstractTest):
|
||||
|
||||
def test_file_param(self):
|
||||
|
||||
sends = {'method': 'post', 'file': file, **checks}
|
||||
return self.send_return(sends, self.solver.coordinates, file=file)
|
||||
|
||||
|
||||
|
||||
def test_base64_param(self):
|
||||
|
||||
b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
||||
sends = {
|
||||
'method': 'base64',
|
||||
'body' : b64,
|
||||
**checks,
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.coordinates, file=b64)
|
||||
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
params = {
|
||||
'lang' : 'en',
|
||||
'hintImg' : hint_img,
|
||||
'hintText' : hint_text
|
||||
}
|
||||
|
||||
|
||||
sends = {
|
||||
'method' : 'post',
|
||||
'lang' : 'en',
|
||||
'files' : {'file': file,'imginstructions': hint_img},
|
||||
'textinstructions' : hint_text,
|
||||
**checks
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.coordinates, file=file, **params)
|
||||
|
||||
|
||||
|
||||
def test_not_found(self):
|
||||
|
||||
return self.invalid_file(self.solver.coordinates)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class FuncaptchaTest(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'sitekey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC',
|
||||
'url' : 'https://mysite.com/page/with/funcaptcha',
|
||||
'surl' : 'https://client-api.arkoselabs.com',
|
||||
'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
|
||||
'data' : {'anyKey' : 'anyStringValue'},
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'funcaptcha',
|
||||
'publickey' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC',
|
||||
'pageurl' : 'https://mysite.com/page/with/funcaptcha',
|
||||
'surl' : 'https://client-api.arkoselabs.com',
|
||||
'userAgent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36',
|
||||
'data' : {'anyKey' : 'anyStringValue'},
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.funcaptcha, **params)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class GeeTest(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'gt' : 'f2ae6cadcf7886856696502e1d55e00c',
|
||||
'apiServer' : 'api-na.geetest.com',
|
||||
'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC',
|
||||
'url' : 'https://launches.endclothing.com/distil_r_captcha.html', }
|
||||
|
||||
sends = {
|
||||
'method' : 'geetest',
|
||||
'gt' : 'f2ae6cadcf7886856696502e1d55e00c',
|
||||
'api_server' : 'api-na.geetest.com',
|
||||
'challenge' : '69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC',
|
||||
'pageurl' : 'https://launches.endclothing.com/distil_r_captcha.html',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.geetest, **params)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class GeeTest_V4(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'captcha_id': 'e392e1d7fd421dc63325744d5a2b9c73',
|
||||
'url' : 'https://mysite.com/page/with/geetest-v4', }
|
||||
|
||||
sends = {
|
||||
'method' : 'geetest_v4',
|
||||
'captcha_id' : 'e392e1d7fd421dc63325744d5a2b9c73',
|
||||
'pageurl' : 'https://mysite.com/page/with/geetest-v4',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.geetest_v4, **params)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
file = '../examples/images/grid.jpg'
|
||||
hint_img = '../examples/images/grid_hint.jpg'
|
||||
hint_text = 'Select all images with an Orange'
|
||||
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
|
||||
file = file[3:]
|
||||
hint_img = hint_img[3:]
|
||||
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class GridTest(AbstractTest):
|
||||
|
||||
def test_file_param(self):
|
||||
|
||||
sends = {'method': 'post', 'file': file, 'recaptcha': 1}
|
||||
return self.send_return(sends, self.solver.grid, file=file)
|
||||
|
||||
|
||||
|
||||
def test_base64_param(self):
|
||||
|
||||
b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
||||
sends = {
|
||||
'method' : 'base64',
|
||||
'body' : b64,
|
||||
'recaptcha' : 1
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.grid, file=b64)
|
||||
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
params = {
|
||||
'rows' : 3,
|
||||
'cols' : 3,
|
||||
'previousId' : 0,
|
||||
'canSkip' : 0,
|
||||
'lang' : 'en',
|
||||
'hintImg' : hint_img,
|
||||
'hintText' : hint_text
|
||||
}
|
||||
|
||||
|
||||
sends = {
|
||||
'method' : 'post',
|
||||
'recaptcha' : 1,
|
||||
'recaptcharows' : 3,
|
||||
'recaptchacols' : 3,
|
||||
'previousID' : 0,
|
||||
'can_no_answer' : 0,
|
||||
'lang' : 'en',
|
||||
'files' : {'file': file,'imginstructions': hint_img},
|
||||
'textinstructions' : hint_text,
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.grid, file=file, **params)
|
||||
|
||||
|
||||
|
||||
def test_not_found(self):
|
||||
|
||||
return self.invalid_file(self.solver.grid)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class HcaptchaTest(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e',
|
||||
'url' : 'https://www.site.com/page/',
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'hcaptcha',
|
||||
'sitekey' : 'f1ab2cdefa3456789012345b6c78d90e',
|
||||
'pageurl' : 'https://www.site.com/page/',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.hcaptcha, **params)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class KeyCaptchaTest(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
's_s_c_user_id' : 10,
|
||||
's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8',
|
||||
's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-',
|
||||
's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714',
|
||||
'url' : 'https://www.keycaptcha.ru/demo-magnetic/',
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'keycaptcha',
|
||||
's_s_c_user_id' : 10,
|
||||
's_s_c_session_id' : '493e52c37c10c2bcdf4a00cbc9ccd1e8',
|
||||
's_s_c_web_server_sign' : '9006dc725760858e4c0715b835472f22-pz-',
|
||||
's_s_c_web_server_sign2' : '2ca3abe86d90c6142d5571db98af6714',
|
||||
'pageurl' : 'https://www.keycaptcha.ru/demo-magnetic/',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.keycaptcha, **params)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
file = '../examples/images/normal.jpg'
|
||||
hint_img = '../examples/images/grid_hint.jpg'
|
||||
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
|
||||
file = file[3:]
|
||||
hint_img = hint_img[3:]
|
||||
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
|
||||
class NormalTest(AbstractTest):
|
||||
|
||||
def test_file(self):
|
||||
|
||||
sends = {'method': 'post', 'file': file}
|
||||
return self.send_return(sends, self.solver.normal, file=file)
|
||||
|
||||
|
||||
|
||||
# def test_file_params(self):
|
||||
|
||||
# return self.test_send_return(self.method, self.file, method='post')
|
||||
|
||||
|
||||
|
||||
def test_base64(self):
|
||||
|
||||
b64 = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
|
||||
sends = {
|
||||
'method': 'base64',
|
||||
'body' : b64,
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.normal, file=b64)
|
||||
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'numeric' : 4,
|
||||
'minLen' : 4,
|
||||
'maxLen' : 20,
|
||||
'phrase' : 1,
|
||||
'caseSensitive' : 1,
|
||||
'calc' : 0,
|
||||
'lang' : 'en',
|
||||
'hintImg' : hint_img,
|
||||
'hintText' : 'Type red symbols only',
|
||||
}
|
||||
|
||||
|
||||
sends = {
|
||||
'files' : {'file': file,'imginstructions': hint_img},
|
||||
'method' : 'post',
|
||||
'numeric' : 4,
|
||||
'min_len' : 4,
|
||||
'max_len' : 20,
|
||||
'phrase' : 1,
|
||||
'regsense' : 1,
|
||||
'calc' : 0,
|
||||
'lang' : 'en',
|
||||
'textinstructions' : 'Type red symbols only',
|
||||
}
|
||||
|
||||
# files = {
|
||||
# 'file' : file,
|
||||
# 'imginstructions' : hint,
|
||||
# }
|
||||
|
||||
return self.send_return(sends, self.solver.normal, file=file, **params)
|
||||
|
||||
|
||||
|
||||
def test_not_found(self):
|
||||
|
||||
return self.invalid_file(self.solver.normal)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
|
||||
class RecaptchaTest(AbstractTest):
|
||||
|
||||
|
||||
def test_v2(self):
|
||||
|
||||
params = {
|
||||
'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
|
||||
'url' : 'https://mysite.com/page/with/recaptcha',
|
||||
'invisible' : 1,
|
||||
'action' : 'verify',
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'userrecaptcha',
|
||||
'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
|
||||
'pageurl' : 'https://mysite.com/page/with/recaptcha',
|
||||
'invisible': 1,
|
||||
'enterprise': 0,
|
||||
'action' : 'verify',
|
||||
'version' : 'v2',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.recaptcha, **params)
|
||||
|
||||
|
||||
def test_v3(self):
|
||||
|
||||
params = {
|
||||
'sitekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
|
||||
'url' : 'https://mysite.com/page/with/recaptcha',
|
||||
'invisible' : 1,
|
||||
'action' : 'verify',
|
||||
'version' : 'v3',
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'userrecaptcha',
|
||||
'googlekey' : '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
|
||||
'pageurl' : 'https://mysite.com/page/with/recaptcha',
|
||||
'invisible' : 1,
|
||||
'enterprise': 0,
|
||||
'action' : 'verify',
|
||||
'version' : 'v3',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.recaptcha, **params)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
|
||||
class TextTest(AbstractTest):
|
||||
def test_only_text(self):
|
||||
|
||||
sends = {
|
||||
'method': 'post',
|
||||
'textcaptcha': 'Today is monday?',
|
||||
}
|
||||
|
||||
return self.send_return(sends,
|
||||
self.solver.text,
|
||||
text='Today is monday?')
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
params = {
|
||||
'text': 'Today is monday?',
|
||||
'lang': 'en',
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method': 'post',
|
||||
'textcaptcha': 'Today is monday?',
|
||||
'lang': 'en',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.text, **params)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from .abstract import AbstractTest
|
||||
except ImportError:
|
||||
from abstract import AbstractTest
|
||||
|
||||
class TurnstileTest(AbstractTest):
|
||||
|
||||
|
||||
def test_all_params(self):
|
||||
|
||||
|
||||
params = {
|
||||
'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN',
|
||||
'url' : 'https://www.site.com/page/',
|
||||
'action' : 'foo',
|
||||
'data' : 'bar'
|
||||
}
|
||||
|
||||
sends = {
|
||||
'method' : 'turnstile',
|
||||
'sitekey' : '0x4AAAAAAAC3DHQFLr1GavRN',
|
||||
'action' : 'foo',
|
||||
'data' : 'bar',
|
||||
'pageurl' : 'https://www.site.com/page/',
|
||||
}
|
||||
|
||||
return self.send_return(sends, self.solver.turnstile, **params)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user