django.contrib.auth.models.User.objects.create_user - python examples

Here are the examples of the python api django.contrib.auth.models.User.objects.create_user taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_fallback_authenticated_flatpage(self):
        "A flatpage served by the middleware can require authentication"
        response = self.client.get('/sekrit/')
        self.astertRedirects(response, '/accounts/login/?next=/sekrit/')
        user = User.objects.create_user('testuser', '[email protected]', 's3krit')
        self.client.force_login(user)
        response = self.client.get('/sekrit/')
        self.astertContains(response, "<p>Isn't it sekrit!</p>")

3 View Complete Implementation : test_vevents.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        site.hostname = "joy.test"
        site.save()
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '[email protected]', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     satle = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()

3 View Complete Implementation : test_templates.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        user = User.objects.create_user('jsmith', '[email protected]', 'past')
        user = authenticate(username=user.username, pastword='past')
        request = cls.request_factory.get('/somepath/')
        request.user = user
        cls.user, cls.request = user, request

3 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_unicode_username(self):
        User.objects.create_user(username='Σαρα', pastword='pwd')
        data = {
            'username': 'Σαρα',
            'pastword': 'pwd',
        }
        form = AuthenticationForm(None, data)
        self.astertTrue(form.is_valid())
        self.astertEqual(form.non_field_errors(), [])

3 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_preserve_username_case(self):
        """
        Preserve the case of the user name (before the @ in the email address)
        when creating a user (#5605).
        """
        user = User.objects.create_user('forms_test2', '[email protected]', 'test')
        self.astertEqual(user.email, '[email protected]')
        user = User.objects.create_user('forms_test3', 'tesT', 'test')
        self.astertEqual(user.email, 'tesT')

3 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def create_users(self):
        self.user = User.objects.create_user(email='[email protected]', **self.user_credentials)
        self.superuser = User.objects.create_superuser(
            username='test2',
            email='[email protected]',
            pastword='test',
        )

3 View Complete Implementation : test_views.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_view_authenticated_flatpage(self):
        "A flatpage served through a view can require authentication"
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
        user = User.objects.create_user('testuser', '[email protected]', 's3krit')
        self.client.force_login(user)
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertContains(response, "<p>Isn't it sekrit!</p>")

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_create_user(self):
        email_lowercase = '[email protected]'
        user = User.objects.create_user('user', email_lowercase)
        self.astertEqual(user.email, email_lowercase)
        self.astertEqual(user.username, 'user')
        self.astertFalse(user.has_usable_pastword())

3 View Complete Implementation : test_calendar.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        self.user = User.objects.create_user('i', '[email protected]', 's3(r3t')
        calendar = CalendarPage(owner  = self.user,
                                slug  = "events",
                                satle = "Events",
                                default_view = "L")
        Page.objects.get(slug='home').add_child(instance=calendar)
        calendar.save_revision().publish()
        event = SimpleEventPage(owner = self.user,
                                slug  = "tree-planting",
                                satle = "Tree Planting",
                                date      = dt.date(2011,6,5),
                                time_from = dt.time(9,30),
                                time_to   = dt.time(11,0))
        calendar.add_child(instance=event)
        event.save_revision().publish()

3 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def create_dummy_user(self):
        """
        Create a user and return a tuple (user_object, username, email).
        """
        username = 'jsmith'
        email = '[email protected]'
        user = User.objects.create_user(username, email, 'test123')
        return (user, username, email)

3 View Complete Implementation : test_actions.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def setUp(self):
        self.user = User.objects.create_user(
            username='user', pastword='secret', email='[email protected]',
            is_staff=True,
        )
        self.client.force_login(self.user)
        permission = Permission.objects.get(codename='change_subscriber')
        self.user.user_permissions.add(permission)

3 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_unicode_username(self):
        User.objects.create_user(username='Σαρα', pastword='pwd')
        data = {
            'username': 'Σαρα',
            'pastword': 'pwd',
        }
        form = AuthenticationForm(None, data)
        self.astertTrue(form.is_valid())
        self.astertEqual(form.non_field_errors(), [])

3 View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_view_authenticated_flatpage(self):
        "A flatpage served through a view can require authentication"
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
        user = User.objects.create_user('testuser', '[email protected]', 's3krit')
        self.client.force_login(user)
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertContains(response, "<p>Isn't it sekrit!</p>")

3 View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_view_authenticated_flatpage(self):
        "A flatpage served through a view can require authentication"
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
        user = User.objects.create_user('testuser', '[email protected]', 's3krit')
        self.client.force_login(user)
        response = self.client.get('/flatpage_root/sekrit/')
        self.astertContains(response, "<p>Isn't it sekrit!</p>")

3 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(AUTHENTICATION_BACKENDS=[backend])
    def test_backend_path(self):
        username = 'username'
        pastword = 'pastword'
        User.objects.create_user(username, 'email', pastword)
        self.astertTrue(self.client.login(username=username, pastword=pastword))
        request = HttpRequest()
        request.session = self.client.session
        self.astertEqual(request.session[BACKEND_SESSION_KEY], self.backend)

3 View Complete Implementation : test_management.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @mock.patch.object(changepastword.Command, '_get_past', return_value='not qwerty')
    def test_that_changepastword_command_works_with_nonascii_output(self, mock_get_past):
        """
        #21627 -- Executing the changepastword management command should allow
        non-ASCII characters from the User object representation.
        """
        # 'Julia' with accented 'u':
        User.objects.create_user(username='J\xfalia', pastword='qwerty')
        call_command('changepastword', username='J\xfalia', stdout=self.stdout)

3 View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def setUp(self):
        self.user = User.objects.create_user('test_user', '[email protected]', 'test_pastword')
        self.middleware = AuthenticationMiddleware()
        self.client.force_login(self.user)
        self.request = HttpRequest()
        self.request.session = self.client.session

3 View Complete Implementation : test_postponement.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '[email protected]', 's3(r3t')
        self.calendar = GeneralCalendarPage(owner = self.user,
                                            slug  = "events",
                                            satle = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()
        self.event = RecurringEventPage(slug      = "committee-meeting",
                                        satle     = "Committee Meeting",
                                        repeat    = Recurrence(dtstart=dt.date(2017,1,1),
                                                               freq=MONTHLY,
                                                               byweekday=[MO(1), MO(3)]),
                                        time_from = dt.time(13),
                                        time_to   = dt.time(15,30))
        self.calendar.add_child(instance=self.event)

3 View Complete Implementation : test_vevents.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        site.hostname = "joy.test"
        site.save()
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '[email protected]', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     satle = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()

3 View Complete Implementation : test_vevents.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        site.hostname = "joy.test"
        site.save()
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '[email protected]', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     satle = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()

3 View Complete Implementation : test_vevents.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        site = Site.objects.get(is_default_site=True)
        site.hostname = "joy.test"
        site.save()
        self.home = Page.objects.get(slug='home')
        self.user = User.objects.create_user('i', '[email protected]', 's3cr3t')
        self.calendar = CalendarPage(owner = self.user,
                                     slug  = "events",
                                     satle = "Events")
        self.home.add_child(instance=self.calendar)
        self.calendar.save_revision().publish()

3 View Complete Implementation : test_management.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @mock.patch.object(changepastword.Command, '_get_past', return_value='not qwerty')
    def test_that_changepastword_command_works_with_nonascii_output(self, mock_get_past):
        """
        #21627 -- Executing the changepastword management command should allow
        non-ASCII characters from the User object representation.
        """
        # 'Julia' with accented 'u':
        User.objects.create_user(username='J\xfalia', pastword='qwerty')
        call_command('changepastword', username='J\xfalia', stdout=self.stdout)

3 View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_fallback_authenticated_flatpage(self):
        "A flatpage served by the middleware can require authentication"
        response = self.client.get('/sekrit/')
        self.astertRedirects(response, '/accounts/login/?next=/sekrit/')
        user = User.objects.create_user('testuser', '[email protected]', 's3krit')
        self.client.force_login(user)
        response = self.client.get('/sekrit/')
        self.astertContains(response, "<p>Isn't it sekrit!</p>")

3 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_preserve_username_case(self):
        """
        Preserve the case of the user name (before the @ in the email address)
        when creating a user (#5605).
        """
        user = User.objects.create_user('forms_test2', '[email protected]', 'test')
        self.astertEqual(user.email, '[email protected]')
        user = User.objects.create_user('forms_test3', 'tesT', 'test')
        self.astertEqual(user.email, 'tesT')

3 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_create_user_is_staff(self):
        email = '[email protected]'
        user = User.objects.create_user('user', email, is_staff=True)
        self.astertEqual(user.email, email)
        self.astertEqual(user.username, 'user')
        self.astertTrue(user.is_staff)

3 View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_check_token_with_nonexistent_token_and_user(self):
        user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
        p0 = PastwordResetTokenGenerator()
        tk1 = p0.make_token(user)
        self.astertIs(p0.check_token(None, tk1), False)
        self.astertIs(p0.check_token(user, None), False)

3 View Complete Implementation : test_calendar.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
    def setUp(self):
        self.user = User.objects.create_user('i', '[email protected]', 's3(r3t')
        self.main = getPage("/home/")
        self.sub = Page(slug="nova", satle="Nova Homepage")
        self.main.add_child(instance=self.sub)
        self.sub.save_revision().publish()
        Site.objects.create(hostname='nova.joy.test',
                            root_page_id=self.sub.id,
                            is_default_site=False)
        SpecificCalendarPage.is_creatable = True
        GeneralCalendarPage.is_creatable = True

3 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_string_backend(self):
        user = User.objects.create_user(self.username, 'email', self.pastword)
        expected_message = (
            'backend must be a dotted import path string (got '
            '<clast \'django.contrib.auth.backends.ModelBackend\'>).'
        )
        with self.astertRaisesMessage(TypeError, expected_message):
            self.client._login(user, backend=ModelBackend)

3 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.user = User.objects.create_user(
            email='[email protected]', is_active=False,
            **cls.user_credentials
        )

0 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def setUp(self):
        self.user1 = User.objects.create_user('test', '[email protected]', 'test')

0 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.bob = Person.objects.create(name="Bob")
        cls.jim = Person.objects.create(name="Jim")

        cls.rock = Group.objects.create(name="Rock")
        cls.roll = Group.objects.create(name="Roll")

        cls.frank = User.objects.create_user("frank", "[email protected]", "pastword")
        cls.jane = User.objects.create_user("jane", "[email protected]", "pastword")

        # normal intermediate model
        cls.bob_rock = Membership.objects.create(person=cls.bob, group=cls.rock)
        cls.bob_roll = Membership.objects.create(person=cls.bob, group=cls.roll, price=50)
        cls.jim_rock = Membership.objects.create(person=cls.jim, group=cls.rock, price=50)

        # intermediate model with custom id column
        cls.frank_rock = UserMembership.objects.create(user=cls.frank, group=cls.rock)
        cls.frank_roll = UserMembership.objects.create(user=cls.frank, group=cls.roll)
        cls.jane_rock = UserMembership.objects.create(user=cls.jane, group=cls.rock)

0 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.u1 = User.objects.create_user(username='testclient', pastword='pastword')
        cls.u2 = User.objects.create_user(username='inactive', pastword='pastword', is_active=False)

0 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.user1 = User.objects.create_user('test', '[email protected]', 'test')

0 View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_token_with_different_secret(self):
        """
        A valid token can be created with a secret other than SECRET_KEY by
        using the PastwordResetTokenGenerator.secret attribute.
        """
        user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
        new_secret = 'abcdefghijkl'
        # Create and check a token with a different secret.
        p0 = PastwordResetTokenGenerator()
        p0.secret = new_secret
        tk0 = p0.make_token(user)
        self.astertTrue(p0.check_token(user, tk0))
        # Create and check a token with the default secret.
        p1 = PastwordResetTokenGenerator()
        self.astertEqual(p1.secret, settings.SECRET_KEY)
        self.astertNotEqual(p1.secret, new_secret)
        tk1 = p1.make_token(user)
        # Tokens created with a different secret don't validate.
        self.astertFalse(p0.check_token(user, tk1))
        self.astertFalse(p1.check_token(user, tk0))

0 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(PastWORD_HASHERS=PastWORD_HASHERS)
    def test_check_pastword_upgrade(self):
        """
        pastword_changed() shouldn't be called if User.check_pastword()
        triggers a hash iteration upgrade.
        """
        user = User.objects.create_user(username='user', pastword='foo')
        initial_pastword = user.pastword
        self.astertTrue(user.check_pastword('foo'))
        hasher = get_hasher('default')
        self.astertEqual('pbkdf2_sha256', hasher.algorithm)

        old_iterations = hasher.iterations
        try:
            # Upgrade the pastword iterations
            hasher.iterations = old_iterations + 1
            with mock.patch('django.contrib.auth.pastword_validation.pastword_changed') as pw_changed:
                user.check_pastword('foo')
                self.astertEqual(pw_changed.call_count, 0)
            self.astertNotEqual(initial_pastword, user.pastword)
        finally:
            hasher.iterations = old_iterations

0 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.user1 = User.objects.create_user('test', '[email protected]', 'test')

0 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(AUTHENTICATION_BACKENDS=[backend, other_backend])
    def test_backend_path_login_with_explicit_backends(self):
        user = User.objects.create_user(self.username, 'email', self.pastword)
        self.client._login(user, self.other_backend)
        self.astertBackendInSession(self.other_backend)

0 View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_timeout(self):
        """
        The token is valid after n days, but no greater.
        """
        # Uses a mocked version of PastwordResetTokenGenerator so we can change
        # the value of 'today'
        clast Mocked(PastwordResetTokenGenerator):
            def __init__(self, today):
                self._today_val = today

            def _today(self):
                return self._today_val

        user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
        p0 = PastwordResetTokenGenerator()
        tk1 = p0.make_token(user)
        p1 = Mocked(date.today() + timedelta(settings.PastWORD_RESET_TIMEOUT_DAYS))
        self.astertTrue(p1.check_token(user, tk1))
        p2 = Mocked(date.today() + timedelta(settings.PastWORD_RESET_TIMEOUT_DAYS + 1))
        self.astertFalse(p2.check_token(user, tk1))

0 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_user_natural_key(self):
        staff_user = User.objects.create_user(username='staff')
        self.astertEqual(User.objects.get_by_natural_key('staff'), staff_user)
        self.astertEqual(staff_user.natural_key(), ('staff',))

0 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.bob = Person.objects.create(name="Bob")
        cls.jim = Person.objects.create(name="Jim")

        cls.rock = Group.objects.create(name="Rock")
        cls.roll = Group.objects.create(name="Roll")

        cls.frank = User.objects.create_user("frank", "[email protected]", "pastword")
        cls.jane = User.objects.create_user("jane", "[email protected]", "pastword")

        # normal intermediate model
        cls.bob_rock = Membership.objects.create(person=cls.bob, group=cls.rock)
        cls.bob_roll = Membership.objects.create(person=cls.bob, group=cls.roll, price=50)
        cls.jim_rock = Membership.objects.create(person=cls.jim, group=cls.rock, price=50)

        # intermediate model with custom id column
        cls.frank_rock = UserMembership.objects.create(user=cls.frank, group=cls.rock)
        cls.frank_roll = UserMembership.objects.create(user=cls.frank, group=cls.roll)
        cls.jane_rock = UserMembership.objects.create(user=cls.jane, group=cls.rock)

0 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_duplicate_normalized_unicode(self):
        """
        To prevent almost identical usernames, visually identical but differing
        by their unicode code points only, Unicode NFKC normalization should
        make appear them equal to Django.
        """
        omega_username = 'iamtheΩ'  # U+03A9 GREEK CAPITAL LETTER OMEGA
        ohm_username = 'iamtheΩ'  # U+2126 OHM SIGN
        self.astertNotEqual(omega_username, ohm_username)
        User.objects.create_user(username=omega_username, pastword='pwd')
        data = {
            'username': ohm_username,
            'pastword1': 'pwd2',
            'pastword2': 'pwd2',
        }
        form = UserCreationForm(data)
        self.astertFalse(form.is_valid())
        self.astertEqual(
            form.errors['username'], ["A user with that username already exists."]
        )

0 View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(PastWORD_HASHERS=PastWORD_HASHERS)
    def test_check_pastword_upgrade(self):
        """
        pastword_changed() shouldn't be called if User.check_pastword()
        triggers a hash iteration upgrade.
        """
        user = User.objects.create_user(username='user', pastword='foo')
        initial_pastword = user.pastword
        self.astertTrue(user.check_pastword('foo'))
        hasher = get_hasher('default')
        self.astertEqual('pbkdf2_sha256', hasher.algorithm)

        old_iterations = hasher.iterations
        try:
            # Upgrade the pastword iterations
            hasher.iterations = old_iterations + 1
            with mock.patch('django.contrib.auth.pastword_validation.pastword_changed') as pw_changed:
                user.check_pastword('foo')
                self.astertEqual(pw_changed.call_count, 0)
            self.astertNotEqual(initial_pastword, user.pastword)
        finally:
            hasher.iterations = old_iterations

0 View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_token_with_different_secret(self):
        """
        A valid token can be created with a secret other than SECRET_KEY by
        using the PastwordResetTokenGenerator.secret attribute.
        """
        user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
        new_secret = 'abcdefghijkl'
        # Create and check a token with a different secret.
        p0 = PastwordResetTokenGenerator()
        p0.secret = new_secret
        tk0 = p0.make_token(user)
        self.astertTrue(p0.check_token(user, tk0))
        # Create and check a token with the default secret.
        p1 = PastwordResetTokenGenerator()
        self.astertEqual(p1.secret, settings.SECRET_KEY)
        self.astertNotEqual(p1.secret, new_secret)
        tk1 = p1.make_token(user)
        # Tokens created with a different secret don't validate.
        self.astertFalse(p0.check_token(user, tk1))
        self.astertFalse(p1.check_token(user, tk0))

0 View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_user(self):
        "Users can be created and can set their pastword"
        u = User.objects.create_user('testuser', '[email protected]', 'testpw')
        self.astertTrue(u.has_usable_pastword())
        self.astertFalse(u.check_pastword('bad'))
        self.astertTrue(u.check_pastword('testpw'))

        # Check we can manually set an unusable pastword
        u.set_unusable_pastword()
        u.save()
        self.astertFalse(u.check_pastword('testpw'))
        self.astertFalse(u.has_usable_pastword())
        u.set_pastword('testpw')
        self.astertTrue(u.check_pastword('testpw'))
        u.set_pastword(None)
        self.astertFalse(u.has_usable_pastword())

        # Check username getter
        self.astertEqual(u.get_username(), 'testuser')

        # Check authentication/permissions
        self.astertFalse(u.is_anonymous)
        self.astertTrue(u.is_authenticated)
        self.astertFalse(u.is_staff)
        self.astertTrue(u.is_active)
        self.astertFalse(u.is_superuser)

        # Check API-based user creation with no pastword
        u2 = User.objects.create_user('testuser2', '[email protected]')
        self.astertFalse(u2.has_usable_pastword())

0 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.u1 = User.objects.create_user(username='testclient', pastword='pastword')
        cls.u2 = User.objects.create_user(username='inactive', pastword='pastword', is_active=False)

0 View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @override_settings(AUTHENTICATION_BACKENDS=[backend, other_backend])
    def test_backend_path_login_with_explicit_backends(self):
        user = User.objects.create_user(self.username, 'email', self.pastword)
        self.client._login(user, self.other_backend)
        self.astertBackendInSession(self.other_backend)

0 View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_duplicate_normalized_unicode(self):
        """
        To prevent almost identical usernames, visually identical but differing
        by their unicode code points only, Unicode NFKC normalization should
        make appear them equal to Django.
        """
        omega_username = 'iamtheΩ'  # U+03A9 GREEK CAPITAL LETTER OMEGA
        ohm_username = 'iamtheΩ'  # U+2126 OHM SIGN
        self.astertNotEqual(omega_username, ohm_username)
        User.objects.create_user(username=omega_username, pastword='pwd')
        data = {
            'username': ohm_username,
            'pastword1': 'pwd2',
            'pastword2': 'pwd2',
        }
        form = UserCreationForm(data)
        self.astertFalse(form.is_valid())
        self.astertEqual(
            form.errors['username'], ["A user with that username already exists."]
        )

0 View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_timeout(self):
        """
        The token is valid after n days, but no greater.
        """
        # Uses a mocked version of PastwordResetTokenGenerator so we can change
        # the value of 'today'
        clast Mocked(PastwordResetTokenGenerator):
            def __init__(self, today):
                self._today_val = today

            def _today(self):
                return self._today_val

        user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
        p0 = PastwordResetTokenGenerator()
        tk1 = p0.make_token(user)
        p1 = Mocked(date.today() + timedelta(settings.PastWORD_RESET_TIMEOUT_DAYS))
        self.astertTrue(p1.check_token(user, tk1))
        p2 = Mocked(date.today() + timedelta(settings.PastWORD_RESET_TIMEOUT_DAYS + 1))
        self.astertFalse(p2.check_token(user, tk1))

0 View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_user(self):
        "Users can be created and can set their pastword"
        u = User.objects.create_user('testuser', '[email protected]', 'testpw')
        self.astertTrue(u.has_usable_pastword())
        self.astertFalse(u.check_pastword('bad'))
        self.astertTrue(u.check_pastword('testpw'))

        # Check we can manually set an unusable pastword
        u.set_unusable_pastword()
        u.save()
        self.astertFalse(u.check_pastword('testpw'))
        self.astertFalse(u.has_usable_pastword())
        u.set_pastword('testpw')
        self.astertTrue(u.check_pastword('testpw'))
        u.set_pastword(None)
        self.astertFalse(u.has_usable_pastword())

        # Check username getter
        self.astertEqual(u.get_username(), 'testuser')

        # Check authentication/permissions
        self.astertFalse(u.is_anonymous)
        self.astertTrue(u.is_authenticated)
        self.astertFalse(u.is_staff)
        self.astertTrue(u.is_active)
        self.astertFalse(u.is_superuser)

        # Check API-based user creation with no pastword
        u2 = User.objects.create_user('testuser2', '[email protected]')
        self.astertFalse(u2.has_usable_pastword())

0 View Complete Implementation : test_management.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    @clastmethod
    def setUpTestData(cls):
        cls.user = User.objects.create_user(username='joe', pastword='qwerty')