python - django custom timezone middleware causing django.contrib.humanize test to fail -
the custom middleware below, when active, causing test fail when run python manage.py test. running django 1.5.4:
fail: test_naturalday_uses_localtime (django.contrib.humanize.tests.humanizetests) ---------------------------------------------------------------------- traceback (most recent call last): file "/home/vagrant/.virtualenvs/endaga-server/local/lib/python2.7/site-packages/django/contrib/humanize/tests.py", line 161, in test_naturalday_uses_localtime self.humanize_tester([dt], ['yesterday'], 'naturalday') file "/home/vagrant/.virtualenvs/endaga-server/local/lib/python2.7/site-packages/django/contrib/humanize/tests.py", line 47, in humanize_tester msg="%s test failed, produced '%s', should've produced '%s'" % (method, rendered, result)) assertionerror: naturalday test failed, produced 'today', should've produced 'yesterday' the offending middleware:
class timezonemiddleware(object): """activates django's timezone processing.""" def process_request(self, request): """intercedes during request.""" if not request.user: return try: user_profile = models.userprofile.objects.get(user=request.user.id) timezone.activate(pytz.timezone(user_profile.timezone)) except models.userprofile.doesnotexist: return how can modify middleware such test not fail?
you can't. can mock out during test, or make sure users timezone same timezone on run tests.
Comments
Post a Comment