Fixed str issues.

see #755
This commit is contained in:
Antoine Nguyen
2017-05-11 09:17:30 +02:00
parent 6644ca3a55
commit 66730da5eb
8 changed files with 16 additions and 25 deletions
+4 -6
View File
@@ -1,7 +1,5 @@
"""Core views test cases."""
import json
from testfixtures import compare
from django import forms
@@ -29,7 +27,7 @@ class LoginTestCase(ModoTestCase):
signals.get_announcements.connect(announcement)
response = self.client.get(reverse("core:login"))
self.assertEqual(response.status_code, 200)
self.assertIn("This is an annoucement!", response.content)
self.assertIn("This is an annoucement!", str(response.content))
class DashboardTestCase(ModoTestCase):
@@ -51,12 +49,12 @@ class DashboardTestCase(ModoTestCase):
url = reverse("core:dashboard")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn("Latest news", response.content)
self.assertIn("Latest news", str(response.content))
self.client.logout()
self.client.login(username=self.dadmin.username, password="toto")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertIn("Latest news", response.content)
self.assertIn("Latest news", str(response.content))
self.client.logout()
self.client.login(username=self.user.username, password="toto")
response = self.client.get(url)
@@ -100,7 +98,7 @@ class DashboardTestCase(ModoTestCase):
url = reverse("core:top_notifications_check")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(json.loads(response.content)), 1)
self.assertEqual(len(response.json()), 1)
class SettingsTestCase(ModoTestCase):
-5
View File
@@ -14,11 +14,6 @@ class SMTPBackend(object):
def authenticate(self, username=None, password=None):
"""Check the username/password and return a User."""
if type(username) is unicode:
username = username.encode("utf-8")
if type(password) is unicode:
password = password.encode("utf-8")
host = getattr(settings, "AUTH_SMTP_SERVER_ADDRESS", "localhost")
port = getattr(settings, "AUTH_SMTP_SERVER_PORT", 25)
secured_mode = getattr(settings, "AUTH_SMTP_SECURED_MODE", None)
+3 -4
View File
@@ -17,7 +17,7 @@ def random_key(l=16):
:return: a string
"""
punctuation = """!#$%&'()*+,-./:;<=>?@[]^_`{|}~"""
population = string.digits + string.letters + punctuation
population = string.digits + string.ascii_letters + punctuation
while True:
key = "".join(random.sample(population * l, l))
if len(key) == l:
@@ -27,13 +27,12 @@ def random_key(l=16):
def encrypt(clear):
key = param_tools.get_global_parameter("secret_key", app="core")
obj = AES.new(key, AES.MODE_ECB)
if type(clear) is unicode:
clear = clear.encode("utf-8")
clear = str(clear)
if len(clear) % AES.block_size:
clear += " " * (AES.block_size - len(clear) % AES.block_size)
ciph = obj.encrypt(clear)
ciph = base64.b64encode(ciph)
return ciph
return str(ciph)
def decrypt(ciph):
+3 -3
View File
@@ -12,7 +12,7 @@ from django.forms.fields import Field
from django.forms.widgets import RadioSelect
from django.forms.widgets import RadioChoiceInput
from django.shortcuts import render
from django.utils.encoding import force_unicode
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _, ugettext_lazy
@@ -376,7 +376,7 @@ class CustomRadioInput(RadioChoiceInput):
label_for = ' for="%s"' % self.attrs["id"]
else:
label_for = ""
choice_label = conditional_escape(force_unicode(self.choice_label))
choice_label = conditional_escape(force_text(self.choice_label))
return mark_safe(
u"<label class='radio-inline' %s>%s %s</label>"
% (label_for, self.tag(), choice_label)
@@ -394,7 +394,7 @@ class InlineRadioRenderer(RadioSelect.renderer):
def render(self):
return mark_safe(
u"\n".join([u"%s\n" % force_unicode(w) for w in self])
u"\n".join([u"%s\n" % force_text(w) for w in self])
)
+1 -1
View File
@@ -143,7 +143,7 @@ def get_object_owner(obj):
def add_permissions_to_group(group, permissions):
"""Add the specified permissions to a django group."""
if isinstance(group, basestring):
if isinstance(group, str):
group = Group.objects.get(name=group)
for appname, modelname, permname in permissions:
+1 -2
View File
@@ -2,7 +2,6 @@
"""Testing utilities."""
from builtins import object
import json
from django.core import management
from django.test import TestCase
@@ -65,7 +64,7 @@ class ModoTestCase(ParametersMixin, TestCase):
response = getattr(self.client, method)(
url, params, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertEqual(response.status_code, status)
return json.loads(response.content)
return response.json()
def ajax_post(self, *args, **kwargs):
return self.ajax_request('post', *args, **kwargs)
+1 -1
View File
@@ -33,7 +33,7 @@ def decode_mime(m):
def u2u_decode(s):
ur"""utility function for (final) decoding of mime header
"""utility function for (final) decoding of mime header
note: resulting string is in one line (no \n within)
note2: spaces between enc_words are stripped (see RFC2047)
+3 -3
View File
@@ -45,9 +45,9 @@ class UTF8EmailValidator(EmailValidator):
ascii_set = u"-!#$%&'*+/=?^_`{}|~0-9A-Z"
user_regex_raw = (
# dot-atom
ur"^[" + ascii_set + ul + "]+(\.[" + ascii_set + ul + "]+)*\Z"
u"^[" + ascii_set + ul + "]+(\.[" + ascii_set + ul + "]+)*\Z"
# quoted-string
ur'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)'
u'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)'
)
user_regex = re.compile("(" + user_regex_raw, re.IGNORECASE)
@@ -59,6 +59,6 @@ class UTF8AndEmptyUserEmailValidator(UTF8EmailValidator):
"""Same as upper + allows empty local part."""
user_regex = re.compile(
ur"(^$|" + UTF8EmailValidator.user_regex_raw, re.IGNORECASE)
u"(^$|" + UTF8EmailValidator.user_regex_raw, re.IGNORECASE)
validate_utf8_and_empty_user_email = UTF8AndEmptyUserEmailValidator()