Skip to content

Commit

Permalink
Replaced all of the u string literal prefixes with six.u() calls and now
Browse files Browse the repository at this point in the history
all tests pass on all supported environments.
  • Loading branch information
amrhassan committed Feb 28, 2014
1 parent 5ef68d3 commit d119b4c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions captcha/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.forms.fields import CharField, MultiValueField
from django.forms.widgets import TextInput, MultiWidget, HiddenInput
from django.utils.translation import ugettext, ugettext_lazy

from six import u

class BaseCaptchaTextInput(MultiWidget):
"""
Expand Down Expand Up @@ -38,7 +38,7 @@ def fetch_captcha_store(self, name, value, attrs=None):
key = CaptchaStore.generate_key()

# these can be used by format_output and render
self._value = [key, u'']
self._value = [key, u('')]
self._key = key
self.id_ = self.build_attrs(attrs).get('id', None)

Expand Down
6 changes: 3 additions & 3 deletions captcha/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
from captcha.conf import settings
from django.core.urlresolvers import reverse

from six import u

def math_challenge():
operators = ('+', '*', '-',)
Expand All @@ -15,14 +15,14 @@ def math_challenge():


def random_char_challenge():
chars, ret = u'abcdefghijklmnopqrstuvwxyz', u''
chars, ret = u('abcdefghijklmnopqrstuvwxyz'), u('')
for i in range(settings.CAPTCHA_LENGTH):
ret += random.choice(chars)
return ret.upper(), ret


def unicode_challenge():
chars, ret = u'äàáëéèïíîöóòüúù', u''
chars, ret = u('äàáëéèïíîöóòüúù'), u('')
for i in range(settings.CAPTCHA_LENGTH):
ret += random.choice(chars)
return ret.upper(), ret
Expand Down
12 changes: 6 additions & 6 deletions captcha/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import re
import six
import os

from six import u

class CaptchaCase(TestCase):
urls = 'captcha.tests.urls'
Expand Down Expand Up @@ -175,7 +175,7 @@ def testRepeatedChallengeFormSubmit(self):

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'
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))
Expand All @@ -186,7 +186,7 @@ def testInvalidOutputFormat(self):
# we turn on DEBUG because CAPTCHA_OUTPUT_FORMAT is only checked debug

django_settings.DEBUG = True
settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s'
settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s')
try:
self.client.get(reverse(urlname))
self.fail()
Expand All @@ -195,14 +195,14 @@ def testInvalidOutputFormat(self):
django_settings.DEBUG = __current_settings_debug

def testPerFormFormat(self):
settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s testCustomFormatString %(hidden_field)s %(text_field)s'
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 testIssue31ProperLabel(self):
settings.CAPTCHA_OUTPUT_FORMAT = u'%(image)s %(hidden_field)s %(text_field)s'
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))

Expand All @@ -226,7 +226,7 @@ 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'
settings.CAPTCHA_OUTPUT_FORMAT = u('%(image)s %(hidden_field)s %(text_field)s')
widget = CaptchaTextInput(attrs={'class': 'required'})
CaptchaField(widget=widget)

Expand Down
6 changes: 3 additions & 3 deletions captcha/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.template import RequestContext, loader
from django.http import HttpResponse
from django.contrib.auth.models import User

from six import u

TEST_TEMPLATE = r'''
{% load url from future %}
Expand Down Expand Up @@ -80,8 +80,8 @@ class CaptchaTestFormatForm(forms.Form):
help_text='asdasd',
error_messages=dict(invalid='TEST CUSTOM ERROR MESSAGE'),
output_format=(
u'%(image)s testPerFieldCustomFormatString '
u'%(hidden_field)s %(text_field)s'
u('%(image)s testPerFieldCustomFormatString '
'%(hidden_field)s %(text_field)s')
)
)
return _test(request, CaptchaTestFormatForm)
Expand Down
9 changes: 5 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# serve to show the default.

import sys, os
from six import u
#sys.path.insert(0, '..')
#import captcha
#print captcha.get_version()
Expand Down Expand Up @@ -40,8 +41,8 @@
master_doc = 'index'

# General information about the project.
project = u'Django Simple Captcha'
copyright = u'2011-2013 Marco Bonetti'
project = u('Django Simple Captcha')
copyright = u('2011-2013 Marco Bonetti')

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -175,8 +176,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'DjangoSimpleCaptcha.tex', u'Django Simple Captcha Documentation',
u'Marco Bonetti', 'manual'),
('index', 'DjangoSimpleCaptcha.tex', u('Django Simple Captcha Documentation'),
u('Marco Bonetti', 'manual')),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down
3 changes: 2 additions & 1 deletion testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import django
import os
import sys
from six import u

SITE_ID = 1

Expand Down Expand Up @@ -36,7 +37,7 @@

LANGUAGES = (
('en', 'English'),
('ja', u'日本語'),
('ja', u('日本語')),
)

SOUTH_TESTS_MIGRATE = False
Expand Down

0 comments on commit d119b4c

Please sign in to comment.