def test_verify_wrong_arguments(self): client = ReCaptchaClient() response = client.verify('', 'test', '127.0.0.1') assert isinstance(httpretty.last_request(), httpretty.core.HTTPrettyRequestEmpty) assert not response.is_valid assert response.error_code == 'incorrect-captcha-sol'
def test_verify_sucess(self): args = urlencode(self.verify_data) httpretty.register_uri(httpretty.GET, 'https://www.google.com/recaptcha/api/verify?' + args, body='true\n\n', status=200, content_type='plain/text') client = ReCaptchaClient() response = client.verify('test', 'test', '127.0.0.1') last_request = httpretty.last_request() assert last_request.path.startswith('/recaptcha/api/verify') assert response.is_valid
def test_render_uses_language(self, render_to_string, activate_en): client = ReCaptchaClient() client.render({'lang': 'de'}, 'foo bar') render_to_string.assert_called_once_with( 'captcha/widget.html', { 'api_server': '//www.google.com/recaptcha/api', 'public_key': 'pubkey', 'lang': 'de', 'options': '{"lang": "de"}', 'challenge_url': '//www.google.com/recaptcha/api/challenge?k=pubkey&hl=de&error=foo+bar', # noqa 'noscript_url': '//www.google.com/recaptcha/api/noscript?k=pubkey&hl=de&error=foo+bar', # noqa })
def test_render_simple(self, render_to_string, activate_en): client = ReCaptchaClient() assert not client.nocaptcha client.render({}) render_to_string.assert_called_once_with( 'captcha/widget.html', { 'api_server': '//www.google.com/recaptcha/api', 'public_key': 'pubkey', 'lang': 'en', 'options': '{"lang": "en"}', 'challenge_url': '//www.google.com/recaptcha/api/challenge?k=pubkey&hl=en', # noqa 'noscript_url': '//www.google.com/recaptcha/api/noscript?k=pubkey&hl=en', # noqa })