Commit cbf36c56 authored by okhin's avatar okhin
Browse files

Merge branch 'python3' into 'master'

Python3 – Unicode

Fix some Python 3 issues (Unicode ones) and remove most of the tests as those ones are related to Unicode.
Everything is Unicode by default with Python 3.

See merge request !1
parents 0acb00ba 312a8535
...@@ -21,7 +21,7 @@ class Campaign(models.Model): ...@@ -21,7 +21,7 @@ class Campaign(models.Model):
choices=LANGUAGES, choices=LANGUAGES,
verbose_name=_('language')) verbose_name=_('language'))
def __unicode__(self): def __str__(self):
return self.title.decode('utf-8') return self.title.decode('utf-8')
...@@ -34,7 +34,7 @@ class Argumentary(models.Model): ...@@ -34,7 +34,7 @@ class Argumentary(models.Model):
verbose_name=_('language')) verbose_name=_('language'))
text = models.TextField(null=True) text = models.TextField(null=True)
def __unicode__(self): def __str__(self):
args = {'lang': self.lang, 'title': self.campaign.title} args = {'lang': self.lang, 'title': self.campaign.title}
return _('Argumentary in %(lang)s for %(title)s') % args return _('Argumentary in %(lang)s for %(title)s') % args
...@@ -46,7 +46,7 @@ class CampaignContact(models.Model): ...@@ -46,7 +46,7 @@ class CampaignContact(models.Model):
contact = models.ForeignKey(Contact) contact = models.ForeignKey(Contact)
weight = models.IntegerField(default=0) weight = models.IntegerField(default=0)
def __unicode__(self): def __str__(self):
args = {'contact': self.contact, 'title': self.campaign.title} args = {'contact': self.contact, 'title': self.campaign.title}
return _('Contact %(contact)s on %(title)s') % args return _('Contact %(contact)s on %(title)s') % args
......
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
from picampaign.campaign.models import Campaign, Argumentary, CampaignContact from picampaign.campaign.models import Campaign, CampaignContact
from picampaign.contact.models import Contact from picampaign.contact.models import Contact
class CampaignMethodTests(TestCase):
def test_unicode_is_title(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
self.assertEqual(campaign.__unicode__(), 'Campaign Title')
def test_unicode_is_unicode(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
self.assertEqual(
str(type(campaign.__unicode__())),
"<type 'unicode'>"
)
class ArgumentaryMethodTests(TestCase):
def test_unicode_is_title(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
argumentary = Argumentary(
campaign=campaign,
lang='en'
)
self.assertEqual(
argumentary.__unicode__(),
"Argumentary in en for Campaign Title"
)
def test_unicode_is_unicode(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
argumentary = Argumentary(
campaign=campaign,
lang='en'
)
self.assertEqual(
str(type(argumentary.__unicode__())),
"<type 'unicode'>"
)
class CampaignContactMethodTests(TestCase): class CampaignContactMethodTests(TestCase):
def test_unicode_is_contact_and_title(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
contact = Contact(
first_name='Victor',
last_name='Hugo',
phone='+3312345678'
)
campaigncontact = CampaignContact(
campaign=campaign,
contact=contact
)
self.assertEqual(
campaigncontact.__unicode__(),
"Contact Victor Hugo on Campaign Title"
)
def test_unicode_is_unicode(self):
campaign = Campaign(
title='Campaign Title',
start_date='2000-01-01',
end_date='2100-12-31'
)
contact = Contact(
first_name='Victor',
last_name='Hugo',
phone='+3312345678'
)
campaigncontact = CampaignContact(
campaign=campaign,
contact=contact
)
self.assertEqual(
str(type(campaigncontact.__unicode__())),
"<type 'unicode'>"
)
def test_all_groups_is_empty(self): def test_all_groups_is_empty(self):
campaign = Campaign( campaign = Campaign(
title='Campaign Title', title='Campaign Title',
......
...@@ -12,7 +12,7 @@ class Contact(models.Model): ...@@ -12,7 +12,7 @@ class Contact(models.Model):
mail = models.CharField(max_length=255, blank=True) mail = models.CharField(max_length=255, blank=True)
photo = models.ImageField(upload_to='contacts/photos', blank=True) photo = models.ImageField(upload_to='contacts/photos', blank=True)
def __unicode__(self): def __str__(self):
return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name, return _(u'%(firstname)s %(lastname)s') % {'firstname': self.first_name,
'lastname': self.last_name} 'lastname': self.last_name}
...@@ -24,5 +24,5 @@ class Contact(models.Model): ...@@ -24,5 +24,5 @@ class Contact(models.Model):
def get_photo_url(self): def get_photo_url(self):
if self.photo: if self.photo:
return self.photo.url return self.photo.url
return u'' return ''
...@@ -10,7 +10,7 @@ class Feedback(models.Model): ...@@ -10,7 +10,7 @@ class Feedback(models.Model):
category = models.ForeignKey(FeedbackCategory) category = models.ForeignKey(FeedbackCategory)
comment = models.CharField(max_length=512, blank=True) comment = models.CharField(max_length=512, blank=True)
def __unicode__(self): def __str__(self):
return _('feedback for %(callee contact)s on %(campaign title)s') % \ return _('feedback for %(callee contact)s on %(campaign title)s') % \
{'callee contact': self.callee.contact, {'callee contact': self.callee.contact,
'campaign title': self.callee.campaign.title} 'campaign title': self.callee.campaign.title}
...@@ -10,7 +10,7 @@ class Organization(models.Model): ...@@ -10,7 +10,7 @@ class Organization(models.Model):
users = models.ManyToManyField(User, null=True, blank=True, users = models.ManyToManyField(User, null=True, blank=True,
related_name='organizations') related_name='organizations')
def __unicode__(self): def __str__(self):
return self.name return self.name
...@@ -19,7 +19,7 @@ class GroupType(models.Model): ...@@ -19,7 +19,7 @@ class GroupType(models.Model):
organization = models.ForeignKey(Organization) organization = models.ForeignKey(Organization)
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
def __unicode__(self): def __str__(self):
return self.name return self.name
...@@ -33,7 +33,7 @@ class Group(models.Model): ...@@ -33,7 +33,7 @@ class Group(models.Model):
contacts = models.ManyToManyField(Contact, null=True, blank=True, contacts = models.ManyToManyField(Contact, null=True, blank=True,
related_name='groups') related_name='groups')
def __unicode__(self): def __str__(self):
return self.name return self.name
...@@ -42,5 +42,5 @@ class FeedbackCategory(models.Model): ...@@ -42,5 +42,5 @@ class FeedbackCategory(models.Model):
name = models.CharField(max_length=64) name = models.CharField(max_length=64)
organization = models.ForeignKey(Organization) organization = models.ForeignKey(Organization)
def __unicode__(self): def __str__(self):
return self.name return self.name
...@@ -12,9 +12,11 @@ requires = [ ...@@ -12,9 +12,11 @@ requires = [
'pillow', 'pillow',
] ]
test_requires = requires + ['pytest']
setup(name='picampaign', setup(name='picampaign',
namespace_packages=['picampaign'], namespace_packages=['picampaign'],
version='0.0.1', version='0.0.2',
description='PiPhone Campaign Manager.', description='PiPhone Campaign Manager.',
long_description=README, long_description=README,
classifiers=["Programming Language :: Python"], classifiers=["Programming Language :: Python"],
...@@ -26,5 +28,5 @@ setup(name='picampaign', ...@@ -26,5 +28,5 @@ setup(name='picampaign',
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
install_requires=requires, install_requires=requires,
tests_require=requires, tests_require=test_requires,
) )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment