What I want to do: I'm trying to run tests with unittest for functions in my views.
Outcome: I'm getting the following error:
....env/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 189, in _fetch "The translation infrastructure cannot be initialized before the " django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
Imports used:
import unittest
from django.test import Client
from django.core.wsgi import get_wsgi_application
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
import sys
sys.path.append('../../mysite/')
from mysite.settings import *
from views import *
application = get_wsgi_application()
As you can see I tried this answer with no success: appregistrynotready-the-translation-infrastructure-cannot-be-initialized
I followed this one too: upgrading-to-django-1-7-getting-appregistrynotready-for-translation-infrastruct
Imports I found with ugettext & ugettext_lazy:
from django.utils.translation import ungettext, ugettext_lazy as _
from django.utils.translation import ungettext, ugettext, ugettext_lazy as _
from django.utils.translation import ugettext_lazy as _
I changed them to
from django.utils.translation import ugettext_lazy as _
But it didn't work either
Some code I found with ugettext
return ugettext('%(number)d %(type)s') % {'number': delta.seconds, 100 'type': count(delta.seconds)}
I was wondering if there could be a problem with this.
I found it worked if I removed this lines from authentication/models.py:
last_pass_change = models.DateTimeField(_("last_pass_change"), default=datetime.datetime.now())
last_failed_login = models.DateTimeField(_("last_failed_login"), default=datetime.datetime.now())
But I don't know how to fix it