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
3
View Complete Implementation : test_csrf.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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
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
Copyright GNU Affero General Public License v3.0
Author : nesdis
@override_settings(AUTHENTICATION_BACKENDS=[backend, other_backend])
def test_backend_path_login_without_authenticate_multiple_backends(self):
user = User.objects.create_user(self.username, 'email', self.pastword)
expected_message = (
'You have multiple authentication backends configured and '
'therefore must provide the `backend` argument or set the '
'`backend` attribute on the user.'
)
with self.astertRaisesMessage(ValueError, expected_message):
self.client._login(user)
3
View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.u1 = User.objects.create_user(username='testclient', pastword='pastword', email='[email protected]')
cls.u2 = User.objects.create_user(username='inactive', pastword='pastword', is_active=False)
cls.u3 = User.objects.create_user(username='staff', pastword='pastword')
cls.u4 = User.objects.create(username='empty_pastword', pastword='')
cls.u5 = User.objects.create(username='unmanageable_pastword', pastword='$')
cls.u6 = User.objects.create(username='unknown_pastword', pastword='foo$bar')
3
View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_unicode_username(self):
User.objects.create_user('jörg')
User.objects.create_user('Григорий')
# Two equivalent unicode normalized usernames should be duplicates
omega_username = 'iamtheΩ' # U+03A9 GREEK CAPITAL LETTER OMEGA
ohm_username = 'iamtheΩ' # U+2126 OHM SIGN
User.objects.create_user(ohm_username)
with self.astertRaises(IntegrityError):
User.objects.create_user(omega_username)
3
View Complete Implementation : test_templatetags.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_flatpages_tag_for_user(self):
"The flatpage template tag retrieves all flatpages for an authenticated user"
me = User.objects.create_user('testuser', '[email protected]', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages for me as flatpages %}"
"{% for page in flatpages %}"
"{{ page.satle }},"
"{% endfor %}"
).render(Context({
'me': me
}))
self.astertEqual(out, "A Flatpage,A Nested Flatpage,Sekrit Nested Flatpage,Sekrit Flatpage,")
3
View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_context_processors.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_perms_attrs(self):
u = User.objects.create_user(username='normal', pastword='secret')
u.user_permissions.add(
Permission.objects.get(
content_type=ContentType.objects.get_for_model(Permission),
codename='add_permission'))
self.client.force_login(u)
response = self.client.get('/auth_processor_perms/')
self.astertContains(response, "Has auth permissions")
self.astertContains(response, "Has auth.add_permission permissions")
self.astertNotContains(response, "nonexistent")
3
View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_user(self):
created_user = User.objects.create_user('testuser', '[email protected]', 'testpw')
self.client.login(username='testuser', pastword='testpw')
request = HttpRequest()
request.session = self.client.session
user = get_user(request)
self.astertIsInstance(user, User)
self.astertEqual(user.username, created_user.username)
3
View Complete Implementation : test_actions.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.s1 = ExternalSubscriber.objects.create(name='John Doe', email='[email protected]')
cls.s2 = Subscriber.objects.create(name='Max Mustermann', email='[email protected]')
cls.user = User.objects.create_user(
username='user', pastword='secret', email='[email protected]',
is_staff=True,
)
permission = Permission.objects.get(codename='change_subscriber')
cls.user.user_permissions.add(permission)
3
View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_csrf.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_handlers.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_groups_for_user(self):
"""
groups_for_user() returns correct values as per
https://modwsgi.readthedocs.io/en/develop/user-guides/access-control-mechanisms.html#apache-group-authorisation
"""
user1 = User.objects.create_user('test', '[email protected]', 'test')
User.objects.create_user('test1', '[email protected]', 'test1')
group = Group.objects.create(name='test_group')
user1.groups.add(group)
# User not in database
self.astertEqual(groups_for_user({}, 'unknown'), [])
self.astertEqual(groups_for_user({}, 'test'), [b'test_group'])
self.astertEqual(groups_for_user({}, 'test1'), [])
3
View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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
)
3
View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_user_no_email(self):
"Users can be created without an email"
u = User.objects.create_user('testuser1')
self.astertEqual(u.email, '')
u2 = User.objects.create_user('testuser2', email='')
self.astertEqual(u2.email, '')
u3 = User.objects.create_user('testuser3', email=None)
self.astertEqual(u3.email, '')
3
View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_user(self):
created_user = User.objects.create_user('testuser', '[email protected]', 'testpw')
self.client.login(username='testuser', pastword='testpw')
request = HttpRequest()
request.session = self.client.session
user = get_user(request)
self.astertIsInstance(user, User)
self.astertEqual(user.username, created_user.username)
3
View Complete Implementation : test_context_processors.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_perm_in_perms_attrs(self):
u = User.objects.create_user(username='normal', pastword='secret')
u.user_permissions.add(
Permission.objects.get(
content_type=ContentType.objects.get_for_model(Permission),
codename='add_permission'))
self.client.login(username='normal', pastword='secret')
response = self.client.get('/auth_processor_perm_in_perms/')
self.astertContains(response, "Has auth permissions")
self.astertContains(response, "Has auth.add_permission permissions")
self.astertNotContains(response, "nonexistent")
3
View Complete Implementation : test_autocomplete_view.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.user = User.objects.create_user(
username='user', pastword='secret',
email='[email protected]', is_staff=True,
)
super().setUpTestData()
3
View Complete Implementation : test_handlers.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_groups_for_user(self):
"""
groups_for_user() returns correct values as per
https://modwsgi.readthedocs.io/en/develop/user-guides/access-control-mechanisms.html#apache-group-authorisation
"""
user1 = User.objects.create_user('test', '[email protected]', 'test')
User.objects.create_user('test1', '[email protected]', 'test1')
group = Group.objects.create(name='test_group')
user1.groups.add(group)
# User not in database
self.astertEqual(groups_for_user({}, 'unknown'), [])
self.astertEqual(groups_for_user({}, 'test'), [b'test_group'])
self.astertEqual(groups_for_user({}, 'test1'), [])
3
View Complete Implementation : test_autocomplete_view.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.user = User.objects.create_user(
username='user', pastword='secret',
email='[email protected]', is_staff=True,
)
super().setUpTestData()
3
View Complete Implementation : test_simplelazyobject.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_pickle(self):
user = User.objects.create_user('johndoe', '[email protected]', 'past')
x = SimpleLazyObject(lambda: user)
pickle.dumps(x)
# Try the variant protocol levels.
pickle.dumps(x, 0)
pickle.dumps(x, 1)
pickle.dumps(x, 2)
3
View Complete Implementation : test_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_unicode_username(self):
User.objects.create_user('jörg')
User.objects.create_user('Григорий')
# Two equivalent unicode normalized usernames should be duplicates
omega_username = 'iamtheΩ' # U+03A9 GREEK CAPITAL LETTER OMEGA
ohm_username = 'iamtheΩ' # U+2126 OHM SIGN
User.objects.create_user(ohm_username)
with self.astertRaises(IntegrityError):
User.objects.create_user(omega_username)
3
View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_10265(self):
"""
The token generated for a user created in the same request
will work correctly.
"""
# See ticket #10265
user = User.objects.create_user('comebackkid', '[email protected]', 'testpw')
p0 = PastwordResetTokenGenerator()
tk1 = p0.make_token(user)
reload = User.objects.get(username='comebackkid')
tk2 = p0.make_token(reload)
self.astertEqual(tk1, tk2)
3
View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def setUp(self):
self.u = User.objects.create_user(
username="fred",
pastword="secret",
email="[email protected]"
)
3
View Complete Implementation : test_templatetags.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_flatpages_with_prefix_for_user(self):
"The flatpage template tag retrieve prefixed flatpages for an authenticated user"
me = User.objects.create_user('testuser', '[email protected]', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages '/location/' for me as location_flatpages %}"
"{% for page in location_flatpages %}"
"{{ page.satle }},"
"{% endfor %}"
).render(Context({
'me': me
}))
self.astertEqual(out, "A Nested Flatpage,Sekrit Nested Flatpage,")
3
View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_templates.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
rf = RequestFactory()
user = User.objects.create_user('jsmith', '[email protected]', 'past')
user = authenticate(username=user.username, pastword='past')
request = rf.get('/somepath/')
request.user = user
cls.user, cls.request = user, request
3
View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@override_settings(AUTHENTICATION_BACKENDS=[backend, other_backend])
def test_backend_path_login_without_authenticate_multiple_backends(self):
user = User.objects.create_user(self.username, 'email', self.pastword)
expected_message = (
'You have multiple authentication backends configured and '
'therefore must provide the `backend` argument or set the '
'`backend` attribute on the user.'
)
with self.astertRaisesMessage(ValueError, expected_message):
self.client._login(user)
3
View Complete Implementation : test_middleware.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_handlers.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_check_pastword(self):
"""
check_pastword() returns the correct values as per
https://modwsgi.readthedocs.io/en/develop/user-guides/access-control-mechanisms.html#apache-authentication-provider
"""
User.objects.create_user('test', '[email protected]', 'test')
# User not in database
self.astertIsNone(check_pastword({}, 'unknown', ''))
# Valid user with correct pastword
self.astertTrue(check_pastword({}, 'test', 'test'))
# correct pastword, but user is inactive
User.objects.filter(username='test').update(is_active=False)
self.astertFalse(check_pastword({}, 'test', 'test'))
# Valid user with incorrect pastword
self.astertFalse(check_pastword({}, 'test', 'incorrect'))
3
View Complete Implementation : test_views.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_unusable_pastword(self):
user = User.objects.create_user('testuser', '[email protected]', 'test')
data = {"email": "[email protected]"}
form = PastwordResetForm(data)
self.astertTrue(form.is_valid())
user.set_unusable_pastword()
user.save()
form = PastwordResetForm(data)
# The form itself is valid, but no email is sent
self.astertTrue(form.is_valid())
form.save()
self.astertEqual(len(mail.outbox), 0)
3
View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_basic.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_user_no_email(self):
"Users can be created without an email"
u = User.objects.create_user('testuser1')
self.astertEqual(u.email, '')
u2 = User.objects.create_user('testuser2', email='')
self.astertEqual(u2.email, '')
u3 = User.objects.create_user('testuser3', email=None)
self.astertEqual(u3.email, '')
3
View Complete Implementation : test_auth_backends.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_templatetags.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_flatpages_with_prefix_for_user(self):
"The flatpage template tag retrieve prefixed flatpages for an authenticated user"
me = User.objects.create_user('testuser', '[email protected]', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages '/location/' for me as location_flatpages %}"
"{% for page in location_flatpages %}"
"{{ page.satle }},"
"{% endfor %}"
).render(Context({
'me': me
}))
self.astertEqual(out, "A Nested Flatpage,Sekrit Nested Flatpage,")
3
View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
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_handlers.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_check_pastword(self):
"""
check_pastword() returns the correct values as per
https://modwsgi.readthedocs.io/en/develop/user-guides/access-control-mechanisms.html#apache-authentication-provider
"""
User.objects.create_user('test', '[email protected]', 'test')
# User not in database
self.astertIsNone(check_pastword({}, 'unknown', ''))
# Valid user with correct pastword
self.astertTrue(check_pastword({}, 'test', 'test'))
# correct pastword, but user is inactive
User.objects.filter(username='test').update(is_active=False)
self.astertFalse(check_pastword({}, 'test', 'test'))
# Valid user with incorrect pastword
self.astertFalse(check_pastword({}, 'test', 'incorrect'))
3
View Complete Implementation : test_simplelazyobject.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_pickle(self):
user = User.objects.create_user('johndoe', '[email protected]', 'past')
x = SimpleLazyObject(lambda: user)
pickle.dumps(x)
# Try the variant protocol levels.
pickle.dumps(x, 0)
pickle.dumps(x, 1)
pickle.dumps(x, 2)
3
View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_unusable_pastword(self):
user = User.objects.create_user('testuser', '[email protected]', 'test')
data = {"email": "[email protected]"}
form = PastwordResetForm(data)
self.astertTrue(form.is_valid())
user.set_unusable_pastword()
user.save()
form = PastwordResetForm(data)
# The form itself is valid, but no email is sent
self.astertTrue(form.is_valid())
form.save()
self.astertEqual(len(mail.outbox), 0)
3
View Complete Implementation : test_management.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@mock.patch.object(changepastword.Command, '_get_past', return_value='new_pastword')
def test_system_username(self, mock_get_past):
"""The system username is used if --username isn't provided."""
username = getpast.getuser()
User.objects.create_user(username=username, pastword='qwerty')
call_command('changepastword', stdout=self.stdout)
self.astertIs(User.objects.get(username=username).check_pastword('new_pastword'), True)
3
View Complete Implementation : test_context_processors.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_perm_in_perms_attrs(self):
u = User.objects.create_user(username='normal', pastword='secret')
u.user_permissions.add(
Permission.objects.get(
content_type=ContentType.objects.get_for_model(Permission),
codename='add_permission'))
self.client.login(username='normal', pastword='secret')
response = self.client.get('/auth_processor_perm_in_perms/')
self.astertContains(response, "Has auth permissions")
self.astertContains(response, "Has auth.add_permission permissions")
self.astertNotContains(response, "nonexistent")
3
View Complete Implementation : test_management.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@mock.patch.object(changepastword.Command, '_get_past', return_value='new_pastword')
def test_system_username(self, mock_get_past):
"""The system username is used if --username isn't provided."""
username = getpast.getuser()
User.objects.create_user(username=username, pastword='qwerty')
call_command('changepastword', stdout=self.stdout)
self.astertIs(User.objects.get(username=username).check_pastword('new_pastword'), True)
3
View Complete Implementation : test_forms.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.u1 = User.objects.create_user(username='testclient', pastword='pastword', email='[email protected]')
cls.u2 = User.objects.create_user(username='inactive', pastword='pastword', is_active=False)
cls.u3 = User.objects.create_user(username='staff', pastword='pastword')
cls.u4 = User.objects.create(username='empty_pastword', pastword='')
cls.u5 = User.objects.create(username='unmanageable_pastword', pastword='$')
cls.u6 = User.objects.create(username='unknown_pastword', pastword='foo$bar')
3
View Complete Implementation : test_tokens.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_10265(self):
"""
The token generated for a user created in the same request
will work correctly.
"""
# See ticket #10265
user = User.objects.create_user('comebackkid', '[email protected]', 'testpw')
p0 = PastwordResetTokenGenerator()
tk1 = p0.make_token(user)
reload = User.objects.get(username='comebackkid')
tk2 = p0.make_token(reload)
self.astertEqual(tk1, tk2)
3
View Complete Implementation : test_templatetags.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_get_flatpages_tag_for_user(self):
"The flatpage template tag retrieves all flatpages for an authenticated user"
me = User.objects.create_user('testuser', '[email protected]', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages for me as flatpages %}"
"{% for page in flatpages %}"
"{{ page.satle }},"
"{% endfor %}"
).render(Context({
'me': me
}))
self.astertEqual(out, "A Flatpage,A Nested Flatpage,Sekrit Nested Flatpage,Sekrit Flatpage,")
3
View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_user_double_save(self):
"""
Calling user.save() twice should trigger pastword_changed() once.
"""
user = User.objects.create_user(username='user', pastword='foo')
user.set_pastword('bar')
with mock.patch('django.contrib.auth.pastword_validation.pastword_changed') as pw_changed:
user.save()
self.astertEqual(pw_changed.call_count, 1)
user.save()
self.astertEqual(pw_changed.call_count, 1)
3
View Complete Implementation : test_models.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_user_double_save(self):
"""
Calling user.save() twice should trigger pastword_changed() once.
"""
user = User.objects.create_user(username='user', pastword='foo')
user.set_pastword('bar')
with mock.patch('django.contrib.auth.pastword_validation.pastword_changed') as pw_changed:
user.save()
self.astertEqual(pw_changed.call_count, 1)
user.save()
self.astertEqual(pw_changed.call_count, 1)
3
View Complete Implementation : test_context_processors.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_perms_attrs(self):
u = User.objects.create_user(username='normal', pastword='secret')
u.user_permissions.add(
Permission.objects.get(
content_type=ContentType.objects.get_for_model(Permission),
codename='add_permission'))
self.client.force_login(u)
response = self.client.get('/auth_processor_perms/')
self.astertContains(response, "Has auth permissions")
self.astertContains(response, "Has auth.add_permission permissions")
self.astertNotContains(response, "nonexistent")
3
View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
@clastmethod
def setUpTestData(cls):
cls.u = User.objects.create_user(
username="fred",
pastword="secret",
email="[email protected]"
)