When I run my project's default tests, one test is failing:
FAIL: test_current_site_in_context_after_login (django.contrib.auth.tests.views.LoginTest)
Traceback (most recent call last): File "/Users/me/Dropbox/dotfiles/.virtualenvs/mysite/lib/python2.7/site-packages/django/contrib/auth/tests/views.py", line 294, in test_current_site_in_context_after_login self.assertEqual(response.context['site_name'], site.name) AssertionError: 'MySite' != u'example.com'
My settings.py file contains:
SITE_NAME = 'MySite'
I load the SITE_NAME in my context at the end of the settings file with:
TEMPLATE_CONTEXT_PROCESSORS = GLOBAL_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'utils.context_processors.mysite',
)
utils/context_processors.py contains:
from mysite import settings
def mysite(request):
return {
'site_name': settings.SITE_NAME,
'request': request
}
I've looked at the source code but I don't understand why the test is comparing my site's name to 'example.com'. I've also looked at the django.contrib.sites.models.Site class and am wondering if I need to clear the Site object cache. However, I don't have a CACHES setting. Could there be some conflict in a .pyc file such that I need to delete all the pyc files in my virtualenv?
BTW, I'm running Django 1.4.2 and 2.7.1.
Thanks very much.
The problem is that you hardcode the SITE_NAME in your settings. You should use Site.objects.get_current()
in your middleware/view instead: https://docs.djangoproject.com/en/1.4/ref/contrib/sites/#hooking-into-the-current-site-from-views