# Path: safety/forms.py
# class PasswordChangeForm(BasePasswordChangeForm):
#     error_messages = dict(BasePasswordChangeForm.error_messages, **{
#         'same_password': _("Your old password and the new one are the same. You must use a different password."),
#     })
# 
#     def clean_new_password2(self):
#         password2 = super(PasswordChangeForm, self).clean_new_password2()
# 
#         if self.user.check_password(password2):
#             raise forms.ValidationError(
#                 self.error_messages['same_password'],
#                 code='same_password')
# 
#         return password2
# 
#     def save(self, *args, **kwargs):
#         pc, created = PasswordChange.objects.get_or_create_for_user(self.user)
#         pc.required = False
#         pc.save()
#         super(PasswordChangeForm, self).save(*args, **kwargs)
# 
# 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/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


from django.core.urlresolvers import reverse
from safety.forms import PasswordChangeForm
from safety.models import PasswordChange, Session
from .base import BaseTestCase
        self.assertTemplateUsed(r, 'safety/password_change/form.html')
        self.assertEqual(r.status_code, 200)

        self.client.logout()

    def test_password_change_done(self):
        self.login_user()

        r = self.client.get(reverse('safety:password_change_done'))
        self.assertTemplateUsed(r, 'safety/password_change/done.html')
        self.assertEqual(r.status_code, 200)

        self.client.logout()

    def test_workflow(self):
        change_form_url = reverse('safety:password_change')

        # We don't have any PasswordChange instance yet.
        # Because we just plugged the app.
        self.assertEqual(PasswordChange.objects.count(), 0)

        # Let's login user.
        self.login_user()

        # We still have no instance.
        self.assertEqual(PasswordChange.objects.count(), 0)

        # Let's create an instance for a given user.
        # By default, "required" field is set to False.
        # So nothing changes.

# Path: safety/forms.py
# class PasswordChangeForm(BasePasswordChangeForm):
#     error_messages = dict(BasePasswordChangeForm.error_messages, **{
#         'same_password': _("Your old password and the new one are the same. You must use a different password."),
#     })
# 
#     def clean_new_password2(self):
#         password2 = super(PasswordChangeForm, self).clean_new_password2()
# 
#         if self.user.check_password(password2):
#             raise forms.ValidationError(
#                 self.error_messages['same_password'],
#                 code='same_password')
# 
#         return password2
# 
#     def save(self, *args, **kwargs):
#         pc, created = PasswordChange.objects.get_or_create_for_user(self.user)
#         pc.required = False
#         pc.save()
#         super(PasswordChangeForm, self).save(*args, **kwargs)
# 
# 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/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/tests/test_views.py
from django.core.urlresolvers import reverse
from safety.forms import PasswordChangeForm
from safety.models import PasswordChange, Session
from .base import BaseTestCase

        self.assertTemplateUsed(r, 'safety/password_change/form.html')
        self.assertEqual(r.status_code, 200)

        self.client.logout()

    def test_password_change_done(self):
        self.login_user()

        r = self.client.get(reverse('safety:password_change_done'))
        self.assertTemplateUsed(r, 'safety/password_change/done.html')
        self.assertEqual(r.status_code, 200)

        self.client.logout()

    def test_workflow(self):
        change_form_url = reverse('safety:password_change')

        # We don't have any PasswordChange instance yet.
        # Because we just plugged the app.
        self.assertEqual(PasswordChange.objects.count(), 0)

        # Let's login user.
        self.login_user()

        # We still have no instance.
        self.assertEqual(PasswordChange.objects.count(), 0)

        # Let's create an instance for a given user.
        # By default, "required" field is set to False.
        # So nothing changes.

        pr, created = PasswordChange.objects.get_or_create_for_user(self.user)