# Path: safety/tests/base.py
# class BaseTestCase(Fixtures, TestCase):
#     def login_user(self, password=None):
#         admin_login_url = reverse('admin:login')
#         password = password or self.USER_PASSWORD
# 
#         self.client.post(
#             admin_login_url,
#             data={
#                 'username': self.user.username,
#                 'password': password,
#                 'next': '/admin/',
#             },
#             REMOTE_ADDR=self.REMOTE_ADDR,
#             HTTP_USER_AGENT=self.UA)
# 
#     def create_fake_sessions(self):
#         store = get_session_store()
# 
#         sessions = []
#         for x in range(10):
#             store.create()
#             session = Session.objects.create(
#                 user=self.user,
#                 session_key=store.session_key,
#                 ip=self.REMOTE_ADDR,
#                 location=self.LOCATION,
#                 device=self.DEVICE,
#                 user_agent=self.UA,
#                 last_activity=now(),
#                 expiration_date=store.get_expiry_date())
#             sessions.append(session)
# 
#         return sessions
# 
# Path: safety/models.py
# class PasswordChange(models.Model):
#     user = models.OneToOneField(
#         getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),
#         verbose_name=_('user'),
#         related_name='safety_password_change')
# 
#     required = models.BooleanField(verbose_name=_('required'), db_index=True, default=False)
#     last_change_date = models.DateTimeField(verbose_name=_('last change date'), null=True, blank=True)
# 
#     objects = managers.PasswordChangeManager()
# 
#     class Meta:
#         verbose_name = _('password change')
#         verbose_name_plural = _('password changes')
# 
#     def __str__(self):
#         return '%s - %s' % (self.user, self.last_change_date)
# 
# class Session(models.Model):
#     user = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), verbose_name=_('user'), null=True)
#     session_key = models.CharField(verbose_name=_('session key'), max_length=40, unique=True)
#     ip = models.GenericIPAddressField(verbose_name=_('IP'))
#     user_agent = models.CharField(verbose_name=_('user agent'), max_length=200)
#     location = models.CharField(verbose_name=_('location'), max_length=255)
#     device = models.CharField(verbose_name=_('device'), max_length=200)
#     expiration_date = models.DateTimeField(verbose_name=_('expiration date'), db_index=True)
#     last_activity = models.DateTimeField(verbose_name=_('last activity'))
#     active = models.BooleanField(default=True)
# 
#     objects = managers.SessionManager()
# 
#     class Meta:
#         verbose_name = _('session')
#         verbose_name_plural = _('sessions')
# 
#     def __str__(self):
#         return '%s (%s)' % (self.user, self.device)
# 
#     def delete_store_session(self):
#         from .utils import get_session_store
# 
#         store = get_session_store()
# 
#         if store.exists(session_key=self.session_key):
#             store.delete(session_key=self.session_key)


from .base import BaseTestCase
from safety.models import (
    PasswordChange,
    Session,
)
# -*- coding: utf-8 -*-



class ModelsTest(BaseTestCase):
    def test_session(self):
        self.assertEqual(Session.objects.count(), 0)
        self.login_user()
        self.assertEqual(Session.objects.count(), 1)
        session = Session.objects.first()
        self.assertTrue(session.active)
        self.client.logout()

# Path: safety/tests/base.py
# class BaseTestCase(Fixtures, TestCase):
#     def login_user(self, password=None):
#         admin_login_url = reverse('admin:login')
#         password = password or self.USER_PASSWORD
# 
#         self.client.post(
#             admin_login_url,
#             data={
#                 'username': self.user.username,
#                 'password': password,
#                 'next': '/admin/',
#             },
#             REMOTE_ADDR=self.REMOTE_ADDR,
#             HTTP_USER_AGENT=self.UA)
# 
#     def create_fake_sessions(self):
#         store = get_session_store()
# 
#         sessions = []
#         for x in range(10):
#             store.create()
#             session = Session.objects.create(
#                 user=self.user,
#                 session_key=store.session_key,
#                 ip=self.REMOTE_ADDR,
#                 location=self.LOCATION,
#                 device=self.DEVICE,
#                 user_agent=self.UA,
#                 last_activity=now(),
#                 expiration_date=store.get_expiry_date())
#             sessions.append(session)
# 
#         return sessions
# 
# Path: safety/models.py
# class PasswordChange(models.Model):
#     user = models.OneToOneField(
#         getattr(settings, 'AUTH_USER_MODEL', 'auth.User'),
#         verbose_name=_('user'),
#         related_name='safety_password_change')
# 
#     required = models.BooleanField(verbose_name=_('required'), db_index=True, default=False)
#     last_change_date = models.DateTimeField(verbose_name=_('last change date'), null=True, blank=True)
# 
#     objects = managers.PasswordChangeManager()
# 
#     class Meta:
#         verbose_name = _('password change')
#         verbose_name_plural = _('password changes')
# 
#     def __str__(self):
#         return '%s - %s' % (self.user, self.last_change_date)
# 
# class Session(models.Model):
#     user = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User'), verbose_name=_('user'), null=True)
#     session_key = models.CharField(verbose_name=_('session key'), max_length=40, unique=True)
#     ip = models.GenericIPAddressField(verbose_name=_('IP'))
#     user_agent = models.CharField(verbose_name=_('user agent'), max_length=200)
#     location = models.CharField(verbose_name=_('location'), max_length=255)
#     device = models.CharField(verbose_name=_('device'), max_length=200)
#     expiration_date = models.DateTimeField(verbose_name=_('expiration date'), db_index=True)
#     last_activity = models.DateTimeField(verbose_name=_('last activity'))
#     active = models.BooleanField(default=True)
# 
#     objects = managers.SessionManager()
# 
#     class Meta:
#         verbose_name = _('session')
#         verbose_name_plural = _('sessions')
# 
#     def __str__(self):
#         return '%s (%s)' % (self.user, self.device)
# 
#     def delete_store_session(self):
#         from .utils import get_session_store
# 
#         store = get_session_store()
# 
#         if store.exists(session_key=self.session_key):
#             store.delete(session_key=self.session_key)


# Path: safety/tests/test_models.py
from .base import BaseTestCase
from safety.models import (
    PasswordChange,
    Session,
)

# -*- coding: utf-8 -*-



class ModelsTest(BaseTestCase):
    def test_session(self):
        self.assertEqual(Session.objects.count(), 0)
        self.login_user()
        self.assertEqual(Session.objects.count(), 1)
        session = Session.objects.first()
        self.assertTrue(session.active)
        self.client.logout()

        self.assertEqual(Session.objects.count(), 1)