Created
May 27, 2012 15:19
-
-
Save reidrac/2814685 to your computer and use it in GitHub Desktop.
Dajango tests using sessions without the Django internal user system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test.client import Client | |
from django.test import TestCase | |
from django.conf import settings | |
from django.utils.importlib import import_module | |
from project.app.models import User | |
class MyTestCase(TestCase): | |
def setUp(self): | |
settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file' | |
engine = import_module(settings.SESSION_ENGINE) | |
store = engine.SessionStore() | |
store.save() | |
self.session = store | |
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key | |
self.user = User.objects.create(name='user', email='user@mail.dom') | |
session = self.session | |
session['user'] = self.user | |
session.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment