Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
7588d7e4
Kaydet (Commit)
7588d7e4
authored
Mar 01, 2017
tarafından
Anton Samarchyan
Kaydeden (comit)
Tim Graham
Mar 01, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improved test coverage for django.contrib.auth.
üst
fede6526
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
6 deletions
+54
-6
test_auth_backends.py
tests/auth_tests/test_auth_backends.py
+19
-6
test_management.py
tests/auth_tests/test_management.py
+28
-0
test_models.py
tests/auth_tests/test_models.py
+7
-0
No files found.
tests/auth_tests/test_auth_backends.py
Dosyayı görüntüle @
7588d7e4
...
...
@@ -583,20 +583,33 @@ class TypeErrorBackend:
raise
TypeError
class
TypeErrorBackendTest
(
TestCase
):
"""
A TypeError within a backend is propagated properly (#18171).
"""
backend
=
'auth_tests.test_auth_backends.TypeErrorBackend'
class
SkippedBackend
:
def
authenticate
(
self
):
# Doesn't accept any credentials so is skipped by authenticate().
pass
class
AuthenticateTests
(
TestCase
):
def
setUp
(
self
):
self
.
user1
=
User
.
objects
.
create_user
(
'test'
,
'test@example.com'
,
'test'
)
@override_settings
(
AUTHENTICATION_BACKENDS
=
[
backend
])
@override_settings
(
AUTHENTICATION_BACKENDS
=
[
'auth_tests.test_auth_backends.TypeErrorBackend'
])
def
test_type_error_raised
(
self
):
"""A TypeError within a backend is propagated properly (#18171)."""
with
self
.
assertRaises
(
TypeError
):
authenticate
(
username
=
'test'
,
password
=
'test'
)
@override_settings
(
AUTHENTICATION_BACKENDS
=
(
'auth_tests.test_auth_backends.SkippedBackend'
,
'django.contrib.auth.backends.ModelBackend'
,
))
def
test_skips_backends_without_arguments
(
self
):
"""
A backend (SkippedBackend) is ignored if it doesn't accept the
credentials as arguments.
"""
self
.
assertEqual
(
authenticate
(
username
=
'test'
,
password
=
'test'
),
self
.
user1
)
class
ImproperlyConfiguredUserModelTest
(
TestCase
):
"""
...
...
tests/auth_tests/test_management.py
Dosyayı görüntüle @
7588d7e4
import
builtins
import
getpass
import
sys
from
datetime
import
date
from
io
import
StringIO
...
...
@@ -110,6 +111,28 @@ class ChangepasswordManagementCommandTestCase(TestCase):
self
.
stdout
.
close
()
self
.
stderr
.
close
()
@mock.patch.object
(
getpass
,
'getpass'
,
return_value
=
'password'
)
def
test_get_pass
(
self
,
mock_get_pass
):
call_command
(
'changepassword'
,
username
=
'joe'
,
stdout
=
self
.
stdout
)
self
.
assertIs
(
User
.
objects
.
get
(
username
=
'joe'
)
.
check_password
(
'password'
),
True
)
@mock.patch.object
(
getpass
,
'getpass'
,
return_value
=
''
)
def
test_get_pass_no_input
(
self
,
mock_get_pass
):
with
self
.
assertRaisesMessage
(
CommandError
,
'aborted'
):
call_command
(
'changepassword'
,
username
=
'joe'
,
stdout
=
self
.
stdout
)
@mock.patch.object
(
changepassword
.
Command
,
'_get_pass'
,
return_value
=
'new_password'
)
def
test_system_username
(
self
,
mock_get_pass
):
"""The system username is used if --username isn't provided."""
username
=
getpass
.
getuser
()
User
.
objects
.
create_user
(
username
=
username
,
password
=
'qwerty'
)
call_command
(
'changepassword'
,
stdout
=
self
.
stdout
)
self
.
assertIs
(
User
.
objects
.
get
(
username
=
username
)
.
check_password
(
'new_password'
),
True
)
def
test_nonexistent_username
(
self
):
with
self
.
assertRaisesMessage
(
CommandError
,
"user 'test' does not exist"
):
call_command
(
'changepassword'
,
username
=
'test'
,
stdout
=
self
.
stdout
)
@mock.patch.object
(
changepassword
.
Command
,
'_get_pass'
,
return_value
=
'not qwerty'
)
def
test_that_changepassword_command_changes_joes_password
(
self
,
mock_get_pass
):
"Executing the changepassword management command should change joe's password"
...
...
@@ -183,6 +206,11 @@ class MultiDBChangepasswordManagementCommandTestCase(TestCase):
)
class
CreatesuperuserManagementCommandTestCase
(
TestCase
):
def
test_no_email_argument
(
self
):
new_io
=
StringIO
()
with
self
.
assertRaisesMessage
(
CommandError
,
'You must use --email with --noinput.'
):
call_command
(
'createsuperuser'
,
interactive
=
False
,
username
=
'joe'
,
stdout
=
new_io
)
def
test_basic_usage
(
self
):
"Check the operation of the createsuperuser management command"
# We can use the management command to create a superuser
...
...
tests/auth_tests/test_models.py
Dosyayı görüntüle @
7588d7e4
...
...
@@ -147,6 +147,13 @@ class UserManagerTestCase(TestCase):
password
=
'test'
,
is_staff
=
False
,
)
def
test_make_random_password
(
self
):
allowed_chars
=
'abcdefg'
password
=
UserManager
()
.
make_random_password
(
5
,
allowed_chars
)
self
.
assertEqual
(
len
(
password
),
5
)
for
char
in
password
:
self
.
assertIn
(
char
,
allowed_chars
)
class
AbstractBaseUserTests
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment