# Path: django_cassandra_engine/sessions/backends/cached_db.py
# class SessionStore(DBStore, CachedStore):
#     """Implements cached, cassandra backed sessions."""
# 
#     cache_key_prefix = KEY_PREFIX
# 
# Path: django_cassandra_engine/sessions/backends/db.py
# class SessionStore(DjangoSessionStore):
#     @classmethod
#     def get_model_class(cls):
#         """Avoid circular import"""
#         from django_cassandra_engine.sessions.models import Session
# 
#         return Session
# 
#     @cached_property
#     def model(self):
#         return self.get_model_class()
# 
#     def create_model_instance(self, data):
#         """
#         Return a new instance of the session model object, which represents the
#         current session state. Intended to be used for saving the session data
#         to the database.
#         :param data:
#         """
#         return self.model(
#             session_key=self._get_or_create_session_key(),
#             session_data=self.encode(data),
#             expire_date=self.get_expiry_date(),
#         )
# 
#     def load(self):
#         try:
#             s = self.model.objects.get(session_key=self.session_key)
#             if s.expire_date <= datetime.now():
#                 s.delete()
#                 raise SuspiciousOperation("old session detected")
#             return self.decode(s.session_data)
#         except (self.model.DoesNotExist, SuspiciousOperation) as e:
#             if isinstance(e, SuspiciousOperation):
#                 logger = logging.getLogger("django.security.%s" % e.__class__.__name__)
#                 logger.warning(force_str(e))
#             self.create()
#             return {}
# 
#     def exists(self, session_key):
#         try:
#             self.model.objects.get(session_key=session_key)
#             return True
#         except self.model.DoesNotExist:
#             return False
# 
#     def save(self, must_create=False):
#         """
#         Saves the current session data to the database. If 'must_create' is
#         True, a database error will be raised if the saving operation doesn't
#         create a *new* entry (as opposed to possibly updating an existing
#         entry).
# 
#         :param must_create:
#         """
#         if self.session_key is None:
#             return self.create()
#         data = self._get_session(no_load=must_create)
#         obj = self.create_model_instance(data)
#         obj.save()
# 
#     def delete(self, session_key=None):
#         if session_key is None:
#             if not self.session_key:
#                 return
#             session_key = self.session_key
# 
#         self.model.objects.filter(session_key=session_key).delete()
# 
#     @classmethod
#     def clear_expired(cls):
#         """TODO: implement this"""
# 
# Path: django_cassandra_engine/test.py
# class TestCase(DjangoTestCase):
#     databases = list(get_cassandra_db_aliases())
# 
#     def _should_reload_connections(self):
#         return False
# 
#     def _fixture_teardown(self):
#         """
#         Allow normal django TestCase fixture teardown, but also flush the test
#         database for each cassandra alias.
#         """
#         super(TestCase, self)._fixture_teardown()
# 
#         for alias, _ in get_cassandra_connections():
#             # Flush the database
#             call_command(
#                 "flush",
#                 verbosity=1,
#                 interactive=False,
#                 database=alias,
#                 skip_checks=True,
#                 reset_sequences=False,
#                 allow_cascade=False,
#                 inhibit_post_migrate=True,
#             )


from datetime import timedelta
from django.conf import settings
from django.core.cache import InvalidCacheBackendError
from django.test.utils import override_settings
from django.utils import timezone
from django.utils.encoding import force_str
from mock import Mock
from django_cassandra_engine.sessions.backends.cached_db import (
    SessionStore as CachedDatabaseSession,
)
from django_cassandra_engine.sessions.backends.db import (
    SessionStore as DatabaseSession,
)
from django_cassandra_engine.test import TestCase
    from django.test.utils import ignore_warnings
import string
import unittest
    def test_session_str(self):
        self.session["x"] = 1
        self.session.save()

        session_key = self.session.session_key
        s = self.model.objects.get(session_key=session_key)

        self.assertEqual(force_str(s), session_key)

    def test_session_get_decoded(self):
        """
        Test we can use Session.get_decoded to retrieve data stored
        in normal way
        """
        self.session["x"] = 1
        self.session.save()

        s = self.model.objects.get(session_key=self.session.session_key)

        self.assertEqual(s.get_decoded(), {"x": 1})

    def test_clearsessions_command(self):
        """
        Test clearsessions command for clearing expired sessions.
        """
        # TODO


class CachedDatabaseSessionTestCase(SessionTestsMixin, TestCase):


# Path: django_cassandra_engine/sessions/backends/cached_db.py
# class SessionStore(DBStore, CachedStore):
#     """Implements cached, cassandra backed sessions."""
# 
#     cache_key_prefix = KEY_PREFIX
# 
# Path: django_cassandra_engine/sessions/backends/db.py
# class SessionStore(DjangoSessionStore):
#     @classmethod
#     def get_model_class(cls):
#         """Avoid circular import"""
#         from django_cassandra_engine.sessions.models import Session
# 
#         return Session
# 
#     @cached_property
#     def model(self):
#         return self.get_model_class()
# 
#     def create_model_instance(self, data):
#         """
#         Return a new instance of the session model object, which represents the
#         current session state. Intended to be used for saving the session data
#         to the database.
#         :param data:
#         """
#         return self.model(
#             session_key=self._get_or_create_session_key(),
#             session_data=self.encode(data),
#             expire_date=self.get_expiry_date(),
#         )
# 
#     def load(self):
#         try:
#             s = self.model.objects.get(session_key=self.session_key)
#             if s.expire_date <= datetime.now():
#                 s.delete()
#                 raise SuspiciousOperation("old session detected")
#             return self.decode(s.session_data)
#         except (self.model.DoesNotExist, SuspiciousOperation) as e:
#             if isinstance(e, SuspiciousOperation):
#                 logger = logging.getLogger("django.security.%s" % e.__class__.__name__)
#                 logger.warning(force_str(e))
#             self.create()
#             return {}
# 
#     def exists(self, session_key):
#         try:
#             self.model.objects.get(session_key=session_key)
#             return True
#         except self.model.DoesNotExist:
#             return False
# 
#     def save(self, must_create=False):
#         """
#         Saves the current session data to the database. If 'must_create' is
#         True, a database error will be raised if the saving operation doesn't
#         create a *new* entry (as opposed to possibly updating an existing
#         entry).
# 
#         :param must_create:
#         """
#         if self.session_key is None:
#             return self.create()
#         data = self._get_session(no_load=must_create)
#         obj = self.create_model_instance(data)
#         obj.save()
# 
#     def delete(self, session_key=None):
#         if session_key is None:
#             if not self.session_key:
#                 return
#             session_key = self.session_key
# 
#         self.model.objects.filter(session_key=session_key).delete()
# 
#     @classmethod
#     def clear_expired(cls):
#         """TODO: implement this"""
# 
# Path: django_cassandra_engine/test.py
# class TestCase(DjangoTestCase):
#     databases = list(get_cassandra_db_aliases())
# 
#     def _should_reload_connections(self):
#         return False
# 
#     def _fixture_teardown(self):
#         """
#         Allow normal django TestCase fixture teardown, but also flush the test
#         database for each cassandra alias.
#         """
#         super(TestCase, self)._fixture_teardown()
# 
#         for alias, _ in get_cassandra_connections():
#             # Flush the database
#             call_command(
#                 "flush",
#                 verbosity=1,
#                 interactive=False,
#                 database=alias,
#                 skip_checks=True,
#                 reset_sequences=False,
#                 allow_cascade=False,
#                 inhibit_post_migrate=True,
#             )


# Path: testproject/sessionsapp/tests/test_sessions.py
from datetime import timedelta
from django.conf import settings
from django.core.cache import InvalidCacheBackendError
from django.test.utils import override_settings
from django.utils import timezone
from django.utils.encoding import force_str
from mock import Mock
from django_cassandra_engine.sessions.backends.cached_db import (
    SessionStore as CachedDatabaseSession,
)
from django_cassandra_engine.sessions.backends.db import (
    SessionStore as DatabaseSession,
)
from django_cassandra_engine.test import TestCase
    from django.test.utils import ignore_warnings
import string
import unittest

    def test_session_str(self):
        self.session["x"] = 1
        self.session.save()

        session_key = self.session.session_key
        s = self.model.objects.get(session_key=session_key)

        self.assertEqual(force_str(s), session_key)

    def test_session_get_decoded(self):
        """
        Test we can use Session.get_decoded to retrieve data stored
        in normal way
        """
        self.session["x"] = 1
        self.session.save()

        s = self.model.objects.get(session_key=self.session.session_key)

        self.assertEqual(s.get_decoded(), {"x": 1})

    def test_clearsessions_command(self):
        """
        Test clearsessions command for clearing expired sessions.
        """
        # TODO


class CachedDatabaseSessionTestCase(SessionTestsMixin, TestCase):


    backend = CachedDatabaseSession