From 19318507d92d35f5f5cee6bfb7c379efa309c4f8 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 4 Feb 2016 11:47:20 -0500 Subject: Stopped registering the sessions tests models to the sessions app. --- tests/sessions_tests/custom_db_backend.py | 43 ------------------------------- tests/sessions_tests/models.py | 40 ++++++++++++++++++++++++++++ tests/sessions_tests/tests.py | 4 +-- 3 files changed, 42 insertions(+), 45 deletions(-) delete mode 100644 tests/sessions_tests/custom_db_backend.py create mode 100644 tests/sessions_tests/models.py diff --git a/tests/sessions_tests/custom_db_backend.py b/tests/sessions_tests/custom_db_backend.py deleted file mode 100644 index 5d4857e5bb..0000000000 --- a/tests/sessions_tests/custom_db_backend.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -This custom Session model adds an extra column to store an account ID. In -real-world applications, it gives you the option of querying the database for -all active sessions for a particular account. -""" -from django.contrib.sessions.backends.db import SessionStore as DBStore -from django.contrib.sessions.base_session import AbstractBaseSession -from django.db import models - - -class CustomSession(AbstractBaseSession): - """ - A session model with a column for an account ID. - """ - account_id = models.IntegerField(null=True, db_index=True) - - class Meta: - app_label = 'sessions' - - @classmethod - def get_session_store_class(cls): - return SessionStore - - -class SessionStore(DBStore): - """ - A database session store, that handles updating the account ID column - inside the custom session model. - """ - @classmethod - def get_model_class(cls): - return CustomSession - - def create_model_instance(self, data): - obj = super(SessionStore, self).create_model_instance(data) - - try: - account_id = int(data.get('_auth_user_id')) - except (ValueError, TypeError): - account_id = None - obj.account_id = account_id - - return obj diff --git a/tests/sessions_tests/models.py b/tests/sessions_tests/models.py new file mode 100644 index 0000000000..7a358595e9 --- /dev/null +++ b/tests/sessions_tests/models.py @@ -0,0 +1,40 @@ +""" +This custom Session model adds an extra column to store an account ID. In +real-world applications, it gives you the option of querying the database for +all active sessions for a particular account. +""" +from django.contrib.sessions.backends.db import SessionStore as DBStore +from django.contrib.sessions.base_session import AbstractBaseSession +from django.db import models + + +class CustomSession(AbstractBaseSession): + """ + A session model with a column for an account ID. + """ + account_id = models.IntegerField(null=True, db_index=True) + + @classmethod + def get_session_store_class(cls): + return SessionStore + + +class SessionStore(DBStore): + """ + A database session store, that handles updating the account ID column + inside the custom session model. + """ + @classmethod + def get_model_class(cls): + return CustomSession + + def create_model_instance(self, data): + obj = super(SessionStore, self).create_model_instance(data) + + try: + account_id = int(data.get('_auth_user_id')) + except (ValueError, TypeError): + account_id = None + obj.account_id = account_id + + return obj diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index c5a7692799..d284dc8236 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -34,7 +34,7 @@ from django.utils import six, timezone from django.utils.encoding import force_text from django.utils.six.moves import http_cookies -from .custom_db_backend import SessionStore as CustomDatabaseSession +from .models import SessionStore as CustomDatabaseSession class SessionTestsMixin(object): @@ -433,7 +433,7 @@ class DatabaseSessionWithTimeZoneTests(DatabaseSessionTests): class CustomDatabaseSessionTests(DatabaseSessionTests): backend = CustomDatabaseSession - session_engine = 'sessions_tests.custom_db_backend' + session_engine = 'sessions_tests.models' def test_extra_session_field(self): # Set the account ID to be picked up by a custom session storage -- cgit v1.3