Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix some tests to be compatible with python3

Roland Geideree4fa4428570
diff --git a/wger/exercises/models.py b/wger/exercises/models.py
index b8b67ef90..58ae54de0 100644
--- a/wger/exercises/models.py
+++ b/wger/exercises/models.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
+import six
import logging
from django.db import models
@@ -321,8 +322,8 @@ class Exercise(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
subject = _('New user submitted exercise')
message = _(u'''The user {0} submitted a new exercise "{1}".'''.format(
request.user.username, self.name))
- mail.mail_admins(unicode(subject),
- unicode(message),
+ mail.mail_admins(six.text_type(subject),
+ six.text_type(message),
fail_silently=True)
@@ -449,8 +450,8 @@ class ExerciseImage(AbstractSubmissionModel, AbstractLicenseModel, models.Model)
request.user.username,
self.name,
self.exercise))
- mail.mail_admins(unicode(subject),
- unicode(message),
+ mail.mail_admins(six.text_type(subject),
+ six.text_type(message),
fail_silently=True)
diff --git a/wger/manager/management/commands/email-reminders.py b/wger/manager/management/commands/email-reminders.py
index 7bfb3bb1c..3c20d182f 100644
--- a/wger/manager/management/commands/email-reminders.py
+++ b/wger/manager/management/commands/email-reminders.py
@@ -65,7 +65,7 @@ class Command(BaseCommand):
if datetime.timedelta(days=profile.workout_reminder) > delta:
if int(options['verbosity']) >= 3:
- print "* Workout '{0}' overdue".format(current_workout)
+ self.stdout.write("* Workout '{0}' overdue".format(current_workout))
counter += 1
self.send_email(profile.user,
@@ -85,7 +85,8 @@ class Command(BaseCommand):
delta = schedule.get_end_date() - datetime.date.today()
if datetime.timedelta(days=profile.workout_reminder) > delta:
if int(options['verbosity']) >= 3:
- print "* Workout '{0}' overdue - schedule".format(schedule_step.workout)
+ self.stdout.write("* Workout '{0}' overdue - schedule".
+ format(schedule_step.workout))
counter += 1
self.send_email(profile.user,
diff --git a/wger/manager/models.py b/wger/manager/models.py
index 8a6d94806..8bb79b286 100644
--- a/wger/manager/models.py
+++ b/wger/manager/models.py
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
+import six
import datetime
import logging
@@ -337,7 +338,7 @@ class Day(models.Model):
'''
Return a more human-readable representation
'''
- return u"{0} for TP {1}".format(self.description, unicode(self.training))
+ return u"{0} for TP {1}".format(self.description, six.text_type(self.training))
def get_owner_object(self):
'''
@@ -456,7 +457,7 @@ class Day(models.Model):
return {'obj': self,
'days_of_week': {
- 'text': u', '.join([unicode(_(i.day_of_week))
+ 'text': u', '.join([six.text_type(_(i.day_of_week))
for i in tmp_days_of_week]),
'day_list': tmp_days_of_week},
'muscles': {
diff --git a/wger/manager/tests/test_ical.py b/wger/manager/tests/test_ical.py
index cf5433e2f..cd2d4be81 100644
--- a/wger/manager/tests/test_ical.py
+++ b/wger/manager/tests/test_ical.py
@@ -139,7 +139,7 @@ class ScheduleICalExportTestCase(WorkoutManagerTestCase):
# Approximate size
self.assertGreater(len(response.content), 1650)
- self.assertLess(len(response.content), 1660)
+ self.assertLess(len(response.content), 1670)
def export_ical(self, fail=False):
'''
@@ -158,7 +158,7 @@ class ScheduleICalExportTestCase(WorkoutManagerTestCase):
# Approximate size
self.assertGreater(len(response.content), 1650)
- self.assertLess(len(response.content), 1660)
+ self.assertLess(len(response.content), 1670)
def test_export_ical_anonymous(self):
'''
diff --git a/wger/manager/tests/test_schedule.py b/wger/manager/tests/test_schedule.py
index e6aa60ad7..03f139bf4 100644
--- a/wger/manager/tests/test_schedule.py
+++ b/wger/manager/tests/test_schedule.py
@@ -12,6 +12,7 @@
#
# You should have received a copy of the GNU Affero General Public License
+import six
import logging
import datetime
@@ -129,7 +130,7 @@ class ScheduleTestCase(WorkoutManagerTestCase):
response.content)
else:
self.assertInHTML('<span class="label label-primary">active</span>',
- response.content)
+ six.text_type(response.content))
schedule = Schedule.objects.get(pk=4)
schedule.is_active = False
schedule.save()
diff --git a/wger/manager/tests/test_set.py b/wger/manager/tests/test_set.py
index 40710b6a6..de95dee70 100644
--- a/wger/manager/tests/test_set.py
+++ b/wger/manager/tests/test_set.py
@@ -75,7 +75,7 @@ class SetAddTestCase(WorkoutManagerAddTestCase):
'exercise2-INITIAL_FORMS': 0,
'exercise2-MAX_NUM_FORMS': 1000,
'exercise2-0-reps': 8}
- response = self.client.post(reverse_lazy('set-add', kwargs={'day_pk': 5}), post_data)
+ response = self.client.post(reverse('set-add', kwargs={'day_pk': 5}), post_data)
self.assertEqual(response.status_code, 302)
set_obj = Set.objects.get(pk=4)
diff --git a/wger/manager/tests/test_weight_log.py b/wger/manager/tests/test_weight_log.py
index 2272c3132..99d0525f9 100644
--- a/wger/manager/tests/test_weight_log.py
+++ b/wger/manager/tests/test_weight_log.py
@@ -128,7 +128,7 @@ class WeightlogTestCase(WorkoutManagerTestCase):
WorkoutLog.objects.all().delete()
l = WorkoutLog()
l.user = user1
- l.date = datetime.date(2014, 01, 05)
+ l.date = datetime.date(2014, 1, 5)
l.exercise = Exercise.objects.get(pk=1)
l.workout = workout1
l.weight = 10
@@ -140,7 +140,7 @@ class WeightlogTestCase(WorkoutManagerTestCase):
session1.workout = workout1
session1.notes = 'Something here'
session1.impression = '3'
- session1.date = datetime.date(2014, 01, 05)
+ session1.date = datetime.date(2014, 1, 5)
session1.save()
session2 = WorkoutSession()
@@ -148,7 +148,7 @@ class WeightlogTestCase(WorkoutManagerTestCase):
session2.workout = workout1
session2.notes = 'Something else here'
session2.impression = '1'
- session2.date = datetime.date(2014, 01, 01)
+ session2.date = datetime.date(2014, 1, 1)
session2.save()
session3 = WorkoutSession()
@@ -156,7 +156,7 @@ class WeightlogTestCase(WorkoutManagerTestCase):
session3.workout = workout2
session3.notes = 'The notes here'
session3.impression = '2'
- session3.date = datetime.date(2014, 01, 05)
+ session3.date = datetime.date(2014, 1, 5)
session3.save()
self.assertEqual(l.get_workout_session(), session1)
diff --git a/wger/manager/tests/test_workout_session.py b/wger/manager/tests/test_workout_session.py
index 4c58db445..6040a9f83 100644
--- a/wger/manager/tests/test_workout_session.py
+++ b/wger/manager/tests/test_workout_session.py
@@ -63,7 +63,7 @@ class EditWorkoutSessionTestCase(WorkoutManagerEditTestCase):
data = {
'user': 1,
'workout': 2,
- 'date': datetime.date(2014, 01, 30),
+ 'date': datetime.date(2014, 1, 30),
'notes': 'My new insights',
'impression': '3',
'time_start': datetime.time(10, 0),
@@ -139,7 +139,7 @@ class WorkoutSessionApiTestCase(api_base_test.ApiBaseResourceTestCase):
resource = WorkoutSession
private_resource = True
data = {'workout': 3,
- 'date': datetime.date(2014, 01, 30),
+ 'date': datetime.date(2014, 1, 30),
'notes': 'My new insights',
'impression': '3',
'time_start': datetime.time(10, 0),
diff --git a/wger/manager/tests/testcase.py b/wger/manager/tests/testcase.py
index 7993f9124..df3867e90 100644
--- a/wger/manager/tests/testcase.py
+++ b/wger/manager/tests/testcase.py
@@ -12,6 +12,7 @@
#
# You should have received a copy of the GNU Affero General Public License
+import six
import os
import decimal
import logging
@@ -23,6 +24,7 @@ from django.core.urlresolvers import NoReverseMatch
from django.core.cache import cache
from django.conf import settings
from django.test import TestCase
+from wger.utils.constants import TWOPLACES
STATUS_CODES_FAIL = (302, 403, 404)
@@ -39,7 +41,7 @@ def get_reverse(url, kwargs={}):
# everything was already done in the individual test case
url = url
- return url
+ return six.text_type(url)
class BaseTestCase(object):
@@ -122,7 +124,7 @@ class WorkoutManagerTestCase(BaseTestCase, TestCase):
current_field_class = field.__class__.__name__
# Standard types, simply compare
- if current_field_class in ('unicode', 'int', 'float', 'time', 'date'):
+ if current_field_class in ('unicode', 'str', 'int', 'float', 'time', 'date'):
self.assertEqual(field, value)
# boolean, convert
@@ -131,7 +133,8 @@ class WorkoutManagerTestCase(BaseTestCase, TestCase):
# decimal, convert
elif current_field_class == 'Decimal':
- self.assertEqual(field, decimal.Decimal(unicode(value)))
+ # TODO: use FOURPLACES when routine branch is merged
+ self.assertEqual(field.quantize(TWOPLACES), decimal.Decimal(value).quantize(TWOPLACES))
# Related manager, iterate
elif current_field_class == 'ManyRelatedManager':
diff --git a/wger/manager/views/ical.py b/wger/manager/views/ical.py
index e1df22fce..a5b52dc8b 100644
--- a/wger/manager/views/ical.py
+++ b/wger/manager/views/ical.py
@@ -14,6 +14,7 @@
#
# You should have received a copy of the GNU Affero General Public License
+import six
import logging
import datetime
@@ -87,7 +88,7 @@ def get_events_workout(calendar, workout, duration, start_date=None):
description_list = []
for set in day['set_list']:
for exercise in set['exercise_list']:
- description_list.append(unicode(exercise['obj']))
+ description_list.append(six.text_type(exercise['obj']))
description = ', '.join(description_list) if description_list else day['obj'].description
# Make an event for each weekday
diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py
index 77e107454..e368feba7 100644
--- a/wger/nutrition/views/plan.py
+++ b/wger/nutrition/views/plan.py
@@ -13,6 +13,8 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
+
+import six
import logging
import datetime
@@ -292,28 +294,32 @@ def export_pdf(request, id, uidb64=None, token=None):
Paragraph(_('Percent of energy'), styleSheet["Normal"]),
Paragraph(_('g per body kg'), styleSheet["Normal"])])
data.append([Paragraph(_('Energy'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['energy']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['energy']), styleSheet["Normal"])])
data.append([Paragraph(_('Protein'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['protein']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['percent']['protein']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['per_kg']['protein']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['protein']), styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['percent']['protein']), styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['per_kg']['protein']), styleSheet["Normal"])])
data.append([Paragraph(_('Carbohydrates'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['carbohydrates']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['percent']['carbohydrates']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['per_kg']['carbohydrates']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['carbohydrates']),
+ styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['percent']['carbohydrates']),
+ styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['per_kg']['carbohydrates']),
+ styleSheet["Normal"])])
data.append([Paragraph(_('Sugar content in carbohydrates'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['carbohydrates_sugar']),
+ Paragraph(six.text_type(plan_data['total']['carbohydrates_sugar']),
styleSheet["Normal"])])
data.append([Paragraph(_('Fat'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['fat']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['percent']['fat']), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['per_kg']['fat']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['fat']), styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['percent']['fat']), styleSheet["Normal"]),
+ Paragraph(six.text_type(plan_data['per_kg']['fat']), styleSheet["Normal"])])
data.append([Paragraph(_('Saturated fat content in fats'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['fat_saturated']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['fat_saturated']),
+ styleSheet["Normal"])])
data.append([Paragraph(_('Fibres'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['fibres']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['fibres']), styleSheet["Normal"])])
data.append([Paragraph(_('Sodium'), styleSheet["Normal"]),
- Paragraph(unicode(plan_data['total']['sodium']), styleSheet["Normal"])])
+ Paragraph(six.text_type(plan_data['total']['sodium']), styleSheet["Normal"])])
table_style = []
table_style.append(('BOX', (0, 0), (-1, -1), 1.25, colors.black))
diff --git a/wger/weight/helpers.py b/wger/weight/helpers.py
index 45cfa4d8f..1b8f849bb 100644
--- a/wger/weight/helpers.py
+++ b/wger/weight/helpers.py
@@ -36,7 +36,7 @@ def parse_weight_csv(request, cleaned_data):
dialect = 'excel'
# csv.reader expects a file-like object, so use StringIO
- parsed_csv = csv.reader(six.StringIO.StringIO(cleaned_data['csv_input']),
+ parsed_csv = csv.reader(six.StringIO(cleaned_data['csv_input']),
dialect)
weight_list = []
diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.py
index 79d97581f..02f031666 100644
--- a/wger/weight/tests/test_entry.py
+++ b/wger/weight/tests/test_entry.py
@@ -13,7 +13,10 @@
# You should have received a copy of the GNU Affero General Public License
import datetime
+import decimal
+
from wger.core.tests import api_base_test
+from wger.utils.constants import TWOPLACES
from wger.weight.models import WeightEntry
@@ -30,7 +33,7 @@ class AddWeightEntryTestCase(WorkoutManagerAddTestCase):
url = 'weight-add'
pk = 8
user_fail = False
- data = {'weight': 81.1,
+ data = {'weight': decimal.Decimal(81.1).quantize(TWOPLACES),
'creation_date': datetime.date(2013, 2, 1),
'user': 1}