Add basic tests

This commit is contained in:
Andrei 2019-02-28 03:55:04 +03:00
parent d29247e7c3
commit b188f7ba9a
3 changed files with 54 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
# Created by .ignore support plugin (hsz.mobi) # Created by .ignore support plugin (hsz.mobi)
.idea/.name .idea/.name
.idea/PythonAntiCaptcha.iml .idea/PythonAntiCaptcha.iml
/test.py
python3_anticaptcha/__pycache__/ python3_anticaptcha/__pycache__/
/.idea/ /.idea/
/python3_anticaptcha.egg-info/ /python3_anticaptcha.egg-info/

16
.travis.yml Normal file
View File

@ -0,0 +1,16 @@
# Disable sudo to speed up the build
sudo: false
# Set the build language to Python
language: python
# Set the python version to 3.6
python: 3.6
# Install the codecov pip dependency
install:
- pip install pytest pytest-cov
# Run the unit test
script:
- pytest test.py --cov=./

38
test.py Normal file
View File

@ -0,0 +1,38 @@
import requests
import python3_anticaptcha
from python3_anticaptcha import NoCaptchaTaskProxyless
class TestAntiCaptcha(object):
def setup_class(self):
#def __init__(self):
self.anticaptcha_key = "ae23fffcfaa29b170e3843e3a486ef19"
self.server_ip = '85.255.8.26'
def test_callback_server(self):
# test server alive
response = requests.get(f'http://{self.server_ip}:8001/ping')
assert response.status_code == 200
# try register new queue
response = requests.post(f'http://{self.server_ip}:8001/register_key',
json={'key':'fwefefefopewofkewopfkop',
'vhost':'anticaptcha_vhost'}
)
assert response.status_code == 200
def test_nocaptcha(self):
nocaptcha = NoCaptchaTaskProxyless.NoCaptchaTaskProxyless(
anticaptcha_key = self.anticaptcha_key,
callbackUrl=f'http://{self.server_ip}:8001/anticaptcha/nocaptcha/fwefefefopewofkewopfkop'
)
# check response type
assert type(nocaptcha) is python3_anticaptcha.NoCaptchaTaskProxyless.NoCaptchaTaskProxyless
response = nocaptcha.captcha_handler(
websiteURL='https://www.google.com/recaptcha/api2/demo',
websiteKey='6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-'
)
# check response type
assert type(response) is dict
# check all dict keys
assert ['errorId', 'errorCode', 'errorDescription'] == list(response.keys())