Fixed #18608 -- Reduced monkey-patching in tests.
Thanks Claude Paroz for the patch.
This commit is contained in:
parent
c54905b359
commit
123362dd37
|
@ -184,7 +184,7 @@ def naturaltime(value):
|
|||
if delta.days != 0:
|
||||
return pgettext(
|
||||
'naturaltime', '%(delta)s ago'
|
||||
) % {'delta': defaultfilters.timesince(value)}
|
||||
) % {'delta': defaultfilters.timesince(value, now)}
|
||||
elif delta.seconds == 0:
|
||||
return _('now')
|
||||
elif delta.seconds < 60:
|
||||
|
@ -206,7 +206,7 @@ def naturaltime(value):
|
|||
if delta.days != 0:
|
||||
return pgettext(
|
||||
'naturaltime', '%(delta)s from now'
|
||||
) % {'delta': defaultfilters.timeuntil(value)}
|
||||
) % {'delta': defaultfilters.timeuntil(value, now)}
|
||||
elif delta.seconds == 0:
|
||||
return _('now')
|
||||
elif delta.seconds < 60:
|
||||
|
|
|
@ -130,7 +130,7 @@ class HumanizeTests(TestCase):
|
|||
def utcoffset(self, dt):
|
||||
return None
|
||||
# we're going to mock datetime.datetime, so use a fixed datetime
|
||||
now = datetime.datetime(2011, 8, 15)
|
||||
now = datetime.datetime(2011, 8, 15, 1, 23)
|
||||
test_list = [
|
||||
now,
|
||||
now - datetime.timedelta(seconds=1),
|
||||
|
@ -185,17 +185,11 @@ class HumanizeTests(TestCase):
|
|||
# equals now.replace(tzinfo=utc)
|
||||
return now.replace(tzinfo=tz) + tz.utcoffset(now)
|
||||
|
||||
# naturaltime also calls timesince/timeuntil
|
||||
from django.contrib.humanize.templatetags import humanize
|
||||
from django.utils import timesince
|
||||
orig_humanize_datetime = humanize.datetime
|
||||
orig_timesince_datetime = timesince.datetime
|
||||
humanize.datetime = MockDateTime
|
||||
timesince.datetime = new.module(b"mock_datetime")
|
||||
timesince.datetime.datetime = MockDateTime
|
||||
|
||||
try:
|
||||
self.humanize_tester(test_list, result_list, 'naturaltime')
|
||||
finally:
|
||||
humanize.datetime = orig_humanize_datetime
|
||||
timesince.datetime = orig_timesince_datetime
|
||||
|
|
Loading…
Reference in New Issue