Skip to content

Commit

Permalink
Fix for recaptcha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Jan 21, 2015
1 parent d2b73ae commit d7dafa5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions flask_wtf/recaptcha/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Recaptcha(object):
'invalid-input-response': 'The response parameter is invalid or malformed.',
}

def __init__(self, message=u'Invalid word. Please try again.'):
def __init__(self, message=None):
if message is None:
message = self._error_codes['missing-input-response']
self.message = message

def __call__(self, form, field):
Expand Down Expand Up @@ -71,6 +73,6 @@ def _validate_recaptcha(self, response, remote_addr):

for error in json_resp["error-codes"]:
if error in self._error_codes:
raise RuntimeError(self._error_codes[error])
raise ValidationError(self._error_codes[error])

return False
13 changes: 7 additions & 6 deletions tests/test_recaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@ def test_recaptcha(self):

def test_invalid_recaptcha(self):
response = self.client.post('/', data={})
assert b'Invalid word' in response.data
assert b'missing' in response.data

def test_send_recaptcha_request(self):
response = self.client.post('/', data={
'recaptcha_response_field': 'test'
'g-recaptcha-response': 'test'
})
assert b'Invalid word' in response.data
assert b'invalid' in response.data

def test_testing(self):
self.app.testing = True
response = self.client.post('/', data={
'recaptcha_response_field': 'test'
'g-recaptcha-response': 'test'
})
assert b'Invalid word' not in response.data
assert b'invalid' not in response.data

def test_no_private_key(self):
self.app.testing = False
self.app.config.pop('RECAPTCHA_PRIVATE_KEY', None)
response = self.client.post('/', data={
'recaptcha_response_field': 'test'
'g-recaptcha-response': 'test'
})
assert response.status_code == 500

Expand Down

0 comments on commit d7dafa5

Please sign in to comment.