Satisfy python2 tests
This commit is contained in:
@@ -15,7 +15,7 @@ from django.db import models
|
|||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.translation import get_language, ugettext_lazy as _
|
from django.utils.translation import get_language, ugettext_lazy as _
|
||||||
from django_countries.fields import CountryField
|
from django_countries.fields import Country, CountryField
|
||||||
|
|
||||||
from .. import choices
|
from .. import choices
|
||||||
from .. import config
|
from .. import config
|
||||||
@@ -326,12 +326,22 @@ class Event(models.Model):
|
|||||||
for field in fields:
|
for field in fields:
|
||||||
field_name = field.name
|
field_name = field.name
|
||||||
from_value = getattr(event, field_name)
|
from_value = getattr(event, field_name)
|
||||||
|
if (isinstance(from_value, datetime.datetime) or
|
||||||
|
isinstance(from_value, datetime.date) or
|
||||||
|
isinstance(from_value, datetime.time) or
|
||||||
|
isinstance(from_value, Country)):
|
||||||
|
from_value = str(from_value)
|
||||||
to_value = getattr(self, field_name)
|
to_value = getattr(self, field_name)
|
||||||
|
if (isinstance(to_value, datetime.datetime) or
|
||||||
|
isinstance(to_value, datetime.date) or
|
||||||
|
isinstance(to_value, datetime.time) or
|
||||||
|
isinstance(to_value, Country)):
|
||||||
|
to_value = str(to_value)
|
||||||
if from_value != to_value:
|
if from_value != to_value:
|
||||||
change = {
|
change = {
|
||||||
'field': field_name,
|
'field': field_name,
|
||||||
'refer': str(from_value),
|
'refer': from_value,
|
||||||
'current': str(to_value),
|
'current': to_value,
|
||||||
}
|
}
|
||||||
changes.append(change)
|
changes.append(change)
|
||||||
diff_text = json.dumps(changes)
|
diff_text = json.dumps(changes)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
@@ -36,19 +37,26 @@ class EventsTestCase(EventMixin, TestCase):
|
|||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
event.country = 'FR'
|
event.country = 'FR'
|
||||||
|
event.save()
|
||||||
|
|
||||||
|
event.trainer_familyname += '-Ömlaut'
|
||||||
event.max_participants = 8
|
event.max_participants = 8
|
||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
changes = event.changes
|
changes = event.changes
|
||||||
self.assertEqual(changes.count(), 2)
|
self.assertEqual(changes.count(), 3)
|
||||||
|
|
||||||
subchanges = json.loads(changes.first().content)
|
subchanges = json.loads(changes.get(pk=1).content)
|
||||||
self.assertEqual(len(subchanges), 3)
|
self.assertEqual(len(subchanges), 3)
|
||||||
self.assertIn({'field': 'alt_first_day', 'refer': 'None', 'current': '2019-03-02'}, subchanges)
|
self.assertIn({'field': 'alt_first_day', 'refer': None, 'current': '2019-03-02'}, subchanges)
|
||||||
self.assertIn({'field': 'sport', 'refer': 'W', 'current': 'M'}, subchanges)
|
self.assertIn({'field': 'sport', 'refer': 'W', 'current': 'M'}, subchanges)
|
||||||
self.assertIn({'field': 'ski_lift', 'refer': 'False', 'current': 'True'}, subchanges)
|
self.assertIn({'field': 'ski_lift', 'refer': False, 'current': True}, subchanges)
|
||||||
|
|
||||||
subchanges = json.loads(changes.last().content)
|
subchanges = json.loads(changes.get(pk=2).content)
|
||||||
self.assertEqual(len(subchanges), 2)
|
self.assertEqual(len(subchanges), 1)
|
||||||
self.assertIn({'field': 'country', 'refer': 'DE', 'current': 'FR'}, subchanges)
|
self.assertIn({'field': 'country', 'refer': 'DE', 'current': 'FR'}, subchanges)
|
||||||
self.assertIn({'field': 'max_participants', 'refer': '0', 'current': '8'}, subchanges)
|
|
||||||
|
subchanges = json.loads(changes.get(pk=3).content)
|
||||||
|
self.assertEqual(len(subchanges), 2)
|
||||||
|
self.assertIn({'field': 'trainer_familyname', 'refer': 'Weißalles', 'current': 'Weißalles-Ömlaut'}, subchanges)
|
||||||
|
self.assertIn({'field': 'max_participants', 'refer': 0, 'current': 8}, subchanges)
|
||||||
|
|||||||
Reference in New Issue
Block a user