示例#1
0
 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))
示例#2
0
 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)
示例#3
0
 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))
示例#4
0
 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')
         )
     )
示例#5
0
 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)
示例#6
0
    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
示例#7
0
    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
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
def unicode_challenge():
    chars, ret = u('äàáëéèïíîöóòüúù'), u('')
    for i in range(settings.CAPTCHA_LENGTH):
        ret += random.choice(chars)
    return ret.upper(), ret
示例#11
0
def random_char_challenge():
    chars, ret = u('abcdefghijklmnopqrstuvwxyz'), u('')
    for i in range(settings.CAPTCHA_LENGTH):
        ret += random.choice(chars)
    return ret.upper(), ret
示例#12
0
 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))
示例#13
0
 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))
示例#14
0
 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))
示例#15
0
 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))