Exemplo n.º 1
0
                           'input',
                           'answer',
                           id=input.id,
                           answer=dict(captcha="invalid test answer"))
    elif step == "timeout":
        pass


def test_input():
    global step

    step = "input"
    text = input.captcha("bildatenlol", "image/jpeg", timeout=0.15)
    print text
    assert text == "invalid test answer"

    step = "timeout"
    try:
        text = input.captcha("bildatenlol", "image/jpeg", timeout=0.1)
        print text
        raise ValueError('InputTimeout exception expected')
    except input.InputTimeout:
        pass


test_input.setUp = lambda: event.add("input:request", send_input)
test_input.tearDown = lambda: event.remove('input:request', send_input)

if __name__ == '__main__':
    test_input()
Exemplo n.º 2
0
                       'answer',
                       id=input.id,
                       answer={'captcha': 'invalid test recaptcha answer'})


def test_recaptcha():
    browser = requests.session()
    resp = browser.get("http://www.google.com/recaptcha/demo/")
    challenge_id = recaptcha.parse(resp.text)

    result, challenge = recaptcha.solve(browser, challenge_id)

    data = {
        "recaptcha_challenge_field": challenge,
        "recaptcha_response_field": result
    }
    resp = browser.post("http://www.google.com/recaptcha/demo/", data=data)

    try:
        assert "Correct" in resp.text or "Incorrect" in resp.text or "Richtig" in resp.text or "Falsch" in resp.text or "Rangt." in resp.text or u"Rétt!" in resp.text or u"Feil." in resp.text or u"Fel." in resp.text
    except:
        print resp.text
        raise


test_recaptcha.setUp = lambda: event.add("input:request", send_input)
test_recaptcha.tearDown = lambda: event.remove('input:request', send_input)

if __name__ == '__main__':
    test_recaptcha()
Exemplo n.º 3
0
import gevent
import requests

from client import interface, event
from client.captcha import recaptcha

def send_input(e, input):
    gevent.spawn_later(0.1, interface.call, 'input', 'answer', id=input.id, answer={'captcha': 'invalid test recaptcha answer'})

def test_recaptcha():
    browser = requests.session()
    resp = browser.get("http://www.google.com/recaptcha/demo/")
    challenge_id = recaptcha.parse(resp.text)

    result, challenge = recaptcha.solve(browser, challenge_id)

    data = {"recaptcha_challenge_field": challenge, "recaptcha_response_field": result}
    resp = browser.post("http://www.google.com/recaptcha/demo/", data=data)

    try:
        assert "Correct" in resp.text or "Incorrect" in resp.text or "Richtig" in resp.text or "Falsch" in resp.text or "Rangt." in resp.text or u"Rétt!" in resp.text or u"Feil." in resp.text or u"Fel." in resp.text
    except:
        print resp.text
        raise

test_recaptcha.setUp = lambda: event.add("input:request", send_input)
test_recaptcha.tearDown = lambda: event.remove('input:request', send_input)

if __name__ == '__main__':
    test_recaptcha()
Exemplo n.º 4
0
def send_input(e, input):
    assert input.timeout > time.time()
    if step == "input":
        gevent.spawn_later(0.1, fake_msg_reset, input)
        gevent.spawn_later(0.2, interface.call, 'input', 'answer', id=input.id, answer=dict(captcha="invalid test answer"))
    elif step == "timeout":
        pass

def test_input():
    global step
    
    step = "input"
    text = input.captcha("bildatenlol", "image/jpeg", timeout=0.15)
    print text
    assert text == "invalid test answer"

    step = "timeout"
    try:
        text = input.captcha("bildatenlol", "image/jpeg", timeout=0.1)
        print text
        raise ValueError('InputTimeout exception expected')
    except input.InputTimeout:
        pass

test_input.setUp = lambda: event.add("input:request", send_input)
test_input.tearDown = lambda: event.remove('input:request', send_input)

if __name__ == '__main__':
    test_input()