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
50b9313e
Kaydet (Commit)
50b9313e
authored
Haz 06, 2014
tarafından
Xavier Fernandez
Kaydeden (comit)
Tim Graham
Haz 13, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22771 -- Fixed test.Client.logout when using custom auth backend.
üst
4696cd96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
5 deletions
+41
-5
client.py
django/test/client.py
+2
-5
auth_backends.py
tests/test_client_regress/auth_backends.py
+20
-0
tests.py
tests/test_client_regress/tests.py
+19
-0
No files found.
django/test/client.py
Dosyayı görüntüle @
50b9313e
...
...
@@ -597,16 +597,13 @@ class Client(RequestFactory):
Causes the authenticated user to be logged out.
"""
from
django.contrib.auth
import
get_user
_model
,
logout
from
django.contrib.auth
import
get_user
,
logout
request
=
HttpRequest
()
engine
=
import_module
(
settings
.
SESSION_ENGINE
)
UserModel
=
get_user_model
()
if
self
.
session
:
request
.
session
=
self
.
session
uid
=
self
.
session
.
get
(
"_auth_user_id"
)
if
uid
:
request
.
user
=
UserModel
.
_default_manager
.
get
(
pk
=
uid
)
request
.
user
=
get_user
(
request
)
else
:
request
.
session
=
engine
.
SessionStore
()
logout
(
request
)
...
...
tests/test_client_regress/auth_backends.py
0 → 100644
Dosyayı görüntüle @
50b9313e
from
django.contrib.auth.backends
import
ModelBackend
from
.models
import
CustomUser
class
CustomUserBackend
(
ModelBackend
):
def
authenticate
(
self
,
username
=
None
,
password
=
None
):
try
:
user
=
CustomUser
.
custom_objects
.
get_by_natural_key
(
username
)
if
user
.
check_password
(
password
):
return
user
except
CustomUser
.
DoesNotExist
:
return
None
def
get_user
(
self
,
user_id
):
try
:
return
CustomUser
.
custom_objects
.
get
(
pk
=
user_id
)
except
CustomUser
.
DoesNotExist
:
return
None
tests/test_client_regress/tests.py
Dosyayı görüntüle @
50b9313e
...
...
@@ -1094,6 +1094,25 @@ class SessionTests(TestCase):
user_logged_out
.
disconnect
(
listener
)
self
.
assertTrue
(
listener
.
executed
)
@override_settings
(
AUTHENTICATION_BACKENDS
=
(
'django.contrib.auth.backends.ModelBackend'
,
'test_client_regress.auth_backends.CustomUserBackend'
))
def
test_logout_with_custom_auth_backend
(
self
):
"Request a logout after logging in with custom authentication backend"
def
listener
(
*
args
,
**
kwargs
):
self
.
assertEqual
(
kwargs
[
'sender'
],
CustomUser
)
listener
.
executed
=
True
listener
.
executed
=
False
u
=
CustomUser
.
custom_objects
.
create
(
email
=
'test@test.com'
)
u
.
set_password
(
'password'
)
u
.
save
()
user_logged_out
.
connect
(
listener
)
self
.
client
.
login
(
username
=
'test@test.com'
,
password
=
'password'
)
self
.
client
.
logout
()
user_logged_out
.
disconnect
(
listener
)
self
.
assertTrue
(
listener
.
executed
)
def
test_logout_without_user
(
self
):
"""Logout should send signal even if user not authenticated."""
def
listener
(
user
,
*
args
,
**
kwargs
):
...
...
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