From 1ca8e133072797c46e5d7fc5bbc110ce5405460b Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Wed, 2 Aug 2017 21:54:43 +0200 Subject: [PATCH 1/2] Convert to bytes. see #1207 --- modoboa/admin/tests/test_export.py | 9 ++++++++- modoboa/core/models.py | 18 +++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modoboa/admin/tests/test_export.py b/modoboa/admin/tests/test_export.py index 5c5f7debd..f7ba5177f 100644 --- a/modoboa/admin/tests/test_export.py +++ b/modoboa/admin/tests/test_export.py @@ -1,3 +1,5 @@ +# coding: utf-8 + """Export related test cases.""" from __future__ import unicode_literals @@ -70,11 +72,16 @@ class ExportTestCase(ModoTestCase): ) def test_export_simpleusers(self): + factories.MailboxFactory( + user__username="toto@test.com", + user__first_name="Léon", user__groups=("SimpleUsers", ), + address="toto", domain__name="test.com", + ) response = self.__export_identities( idtfilter="account", grpfilter="SimpleUsers" ) self.assertListEqual( - "account;user@test.com;{PLAIN}toto;;;True;SimpleUsers;user@test.com;10\r\naccount;user@test2.com;{PLAIN}toto;;;True;SimpleUsers;user@test2.com;10", + "account;user@test.com;{PLAIN}toto;;;True;SimpleUsers;user@test.com;10\r\naccount;user@test2.com;{PLAIN}toto;;;True;SimpleUsers;user@test2.com;10\r\naccount;toto@test.com;{PLAIN}toto;Léon;;True;SimpleUsers;toto@test.com;10", response.content.strip() ) diff --git a/modoboa/core/models.py b/modoboa/core/models.py index a118d52e2..d728c203c 100644 --- a/modoboa/core/models.py +++ b/modoboa/core/models.py @@ -8,7 +8,7 @@ import re from django.core.urlresolvers import reverse from django.db import models from django.utils.encoding import ( - python_2_unicode_compatible, smart_bytes, smart_text, force_str, force_text + python_2_unicode_compatible, smart_bytes, smart_text, force_str ) from django.utils.functional import cached_property from django.utils.translation import ugettext as _, ugettext_lazy @@ -365,14 +365,14 @@ class User(AbstractUser): :param csvwriter: csv object """ row = [ - "account", - force_text(self.username), - force_text(self.password), - force_text(self.first_name), - force_text(self.last_name), - force_text(self.is_active), - force_text(self.role), - force_text(self.email) + b"account", + smart_bytes(self.username), + smart_bytes(self.password), + smart_bytes(self.first_name), + smart_bytes(self.last_name), + smart_bytes(self.is_active), + smart_bytes(self.role), + smart_bytes(self.email) ] results = signals.account_exported.send( sender=self.__class__, user=self) From 3afc2a983c3ca6d91928d532fea43c93c7fa9234 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 4 Aug 2017 09:51:03 +0200 Subject: [PATCH 2/2] We need str objects here. see #1207 --- modoboa/core/models.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modoboa/core/models.py b/modoboa/core/models.py index d728c203c..0d2b203f4 100644 --- a/modoboa/core/models.py +++ b/modoboa/core/models.py @@ -365,14 +365,14 @@ class User(AbstractUser): :param csvwriter: csv object """ row = [ - b"account", - smart_bytes(self.username), - smart_bytes(self.password), - smart_bytes(self.first_name), - smart_bytes(self.last_name), - smart_bytes(self.is_active), - smart_bytes(self.role), - smart_bytes(self.email) + "account", + force_str(self.username), + force_str(self.password), + force_str(self.first_name), + force_str(self.last_name), + force_str(self.is_active), + force_str(self.role), + force_str(self.email) ] results = signals.account_exported.send( sender=self.__class__, user=self)