<commit_before># coding: utf-8

import unittest
from test.factories import UserFactory

from django.contrib.auth.models import User
from django.db.models.signals import post_save

from users.models import create_new_user, Users


class UserTest(unittest.TestCase):
    '''User-specific tests'''
    def setUp(self):
        self.user = UserFactory.build()

    def tearDown(self):
        self.user = None

    def test_user(self):
        self.assertNotEqual(None, self.user)
        self.assertEqual('Boy', self.user.first_name)
        self.assertEqual('Factory', self.user.last_name)
        self.assertEqual('<EMAIL>', self.user.email)

    def test_user_generator(self):
        pass

    def test_create_new_user(self):
        self.assertEqual(0, User.objects.all().count())
        create_new_user(
            first_name = self.user.first_name,
            last_name = self.user.last_name,
            email = self.user.email,
            password='<PASSWORD>'
        )
        self.assertEqual(1, User.objects.all().count())
        u = User.objects.get(email=self.user.email)
        self.assertEqual(u.first_name, self.user.first_name)
        self.assertEqual(u.last_name, self.user.last_name)
        self.assertTrue(u.check_password('<PASSWORD>'))
        self.assertFalse(u.is_staff)
        self.assertFalse(u.is_active)
<commit_msg>Test user password change on authentication<commit_after># coding: utf-8

import unittest
from test.factories import UserFactory

from django.contrib.auth.models import User
from django.db.models.signals import post_save

from core.backends import IonAuth
from users.models import create_new_user, Users


class UserTest(unittest.TestCase):
    '''User-specific tests'''
    def setUp(self):
        self.user = UserFactory.build()

    def tearDown(self):
        self.user = None

    def test_user(self):
        self.assertNotEqual(None, self.user)
        self.assertEqual('Boy', self.user.first_name)
        self.assertEqual('Factory', self.user.last_name)
        self.assertEqual('<EMAIL>', self.user.email)

    def test_user_generator(self):
        pass

    def test_create_new_user(self):
        self.assertEqual(0, User.objects.all().count())
        create_new_user(
            first_name = self.user.first_name,
            last_name = self.user.last_name,
            email = self.user.email,
            password='<PASSWORD>'
        )
        self.assertEqual(1, User.objects.all().count())
        u = User.objects.get(email=self.user.email)
        self.assertEqual(u.first_name, self.user.first_name)
        self.assertEqual(u.last_name, self.user.last_name)
        self.assertTrue(u.check_password('<PASSWORD>'))
        self.assertFalse(u.is_staff)
        self.assertFalse(u.is_active)


class AuthTest(unittest.TestCase):
    '''Authorization tests'''
    def test_ion_auth(self):
        self.assertEquals(40, len(self.user.password))
        
    def setUp(self):
        self.user = UserFactory.build(
            password = IonAuth().password_hash('<PASSWORD>')
        )

    def tearDown(self):
        self.user = None

    def test_password_rewrite(self):
        self.user.save()
        ion_pass = self.user.password
        ion = IonAuth()
        u2 = ion.authenticate(self.user.email, '123')
        self.assertIsNotNone(u2)
        self.assertFalse(u2.is_anonymous())
        self.assertNotEqual(self.user.password, u2.password)
        self.user.delete()

{'fraction_non_alphanumeric': 0.11786852012742542, 'fraction_numerical': 0.004344048653344918, 'mean_word_length': 2.762527233115468, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6414342', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1044, 'n_words': 182}