def testPerFormFormat(self): settings.CAPTCHA_OUTPUT_FORMAT = u( '%(image)s testCustomFormatString %(hidden_field)s %(text_field)s') r = self.client.get(reverse('captcha-test')) self.assertTrue('testCustomFormatString' in str(r.content)) r = self.client.get(reverse('test_per_form_format')) self.assertTrue('testPerFieldCustomFormatString' in str(r.content))
def testIssue12ProperInstantiation(self): """ This test covers a default django field and widget behavior It not assert anything. If something is wrong it will raise a error! """ settings.CAPTCHA_OUTPUT_FORMAT = u("%(image)s %(hidden_field)s %(text_field)s") widget = CaptchaTextInput(attrs={"class": "required"}) CaptchaField(widget=widget)
def testOutputFormat(self): for urlname in ('captcha-test', 'captcha-test-model-form'): settings.CAPTCHA_OUTPUT_FORMAT = u( '%(image)s<p>Hello, captcha world</p>%(hidden_field)s%(text_field)s' ) r = self.client.get(reverse(urlname)) self.assertEqual(r.status_code, 200) self.assertTrue('<p>Hello, captcha world</p>' in str(r.content))
class CaptchaTestFormatForm(forms.Form): captcha = CaptchaField( help_text='asdasd', error_messages=dict(invalid='TEST CUSTOM ERROR MESSAGE'), output_format=( u('%(image)s testPerFieldCustomFormatString ' '%(hidden_field)s %(text_field)s') ) )
def testIssue12ProperInstantiation(self): """ This test covers a default django field and widget behavior It not assert anything. If something is wrong it will raise a error! """ settings.CAPTCHA_OUTPUT_FORMAT = u( '%(image)s %(hidden_field)s %(text_field)s') widget = CaptchaTextInput(attrs={'class': 'required'}) CaptchaField(widget=widget)
def testInvalidOutputFormat(self): __current_settings_debug = django_settings.DEBUG for urlname in ("captcha-test", "captcha-test-model-form"): # we turn on DEBUG because CAPTCHA_OUTPUT_FORMAT is only checked debug django_settings.DEBUG = True settings.CAPTCHA_OUTPUT_FORMAT = u("%(image)s") try: self.client.get(reverse(urlname)) self.fail() except ImproperlyConfigured as e: self.assertTrue("CAPTCHA_OUTPUT_FORMAT" in str(e)) django_settings.DEBUG = __current_settings_debug
def testInvalidOutputFormat(self): __current_settings_debug = django_settings.DEBUG for urlname in ('captcha-test', 'captcha-test-model-form'): # we turn on DEBUG because CAPTCHA_OUTPUT_FORMAT is only checked debug django_settings.DEBUG = True settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s') try: self.client.get(reverse(urlname)) self.fail() except ImproperlyConfigured as e: self.assertTrue('CAPTCHA_OUTPUT_FORMAT' in str(e)) django_settings.DEBUG = __current_settings_debug
def fetch_captcha_store(self, name, value, attrs=None): """ Fetches a new CaptchaStore This has to be called inside render """ try: reverse('captcha-image', args=('dummy',)) except NoReverseMatch: raise ImproperlyConfigured('Make sure you\'ve included captcha.urls as explained in the INSTALLATION section on http://readthedocs.org/docs/django-simple-captcha/en/latest/usage.html#installation') key = CaptchaStore.generate_key() # these can be used by format_output and render self._value = [key, u('')] self._key = key self.id_ = self.build_attrs(attrs).get('id', None)
def fetch_captcha_store(self, name, value, attrs=None): """ Fetches a new CaptchaStore This has to be called inside render """ try: reverse('captcha-image', args=('dummy', )) except NoReverseMatch: raise ImproperlyConfigured( 'Make sure you\'ve included captcha.urls as explained in the INSTALLATION section on http://readthedocs.org/docs/django-simple-captcha/en/latest/usage.html#installation' ) key = CaptchaStore.generate_key() # these can be used by format_output and render self._value = [key, u('')] self._key = key self.id_ = self.build_attrs(attrs).get('id', None)
def unicode_challenge(): chars, ret = u('äàáëéèïíîöóòüúù'), u('') for i in range(settings.CAPTCHA_LENGTH): ret += random.choice(chars) return ret.upper(), ret
def random_char_challenge(): chars, ret = u('abcdefghijklmnopqrstuvwxyz'), u('') for i in range(settings.CAPTCHA_LENGTH): ret += random.choice(chars) return ret.upper(), ret
def testIssue31ProperLabel(self): settings.CAPTCHA_OUTPUT_FORMAT = u("%(image)s %(hidden_field)s %(text_field)s") r = self.client.get(reverse("captcha-test")) self.assertTrue('<label for="id_captcha_1"' in str(r.content))
def testPerFormFormat(self): settings.CAPTCHA_OUTPUT_FORMAT = u("%(image)s testCustomFormatString %(hidden_field)s %(text_field)s") r = self.client.get(reverse("captcha-test")) self.assertTrue("testCustomFormatString" in str(r.content)) r = self.client.get(reverse("test_per_form_format")) self.assertTrue("testPerFieldCustomFormatString" in str(r.content))
def testOutputFormat(self): for urlname in ("captcha-test", "captcha-test-model-form"): settings.CAPTCHA_OUTPUT_FORMAT = u("%(image)s<p>Hello, captcha world</p>%(hidden_field)s%(text_field)s") r = self.client.get(reverse(urlname)) self.assertEqual(r.status_code, 200) self.assertTrue("<p>Hello, captcha world</p>" in str(r.content))
def testIssue31ProperLabel(self): settings.CAPTCHA_OUTPUT_FORMAT = u( '%(image)s %(hidden_field)s %(text_field)s') r = self.client.get(reverse('captcha-test')) self.assertTrue('<label for="id_captcha_1"' in str(r.content))