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
867d287b
Kaydet (Commit)
867d287b
authored
Agu 18, 2015
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added a test to ensure empty sessions are saved.
üst
333cbdcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
tests.py
tests/sessions_tests/tests.py
+39
-0
No files found.
tests/sessions_tests/tests.py
Dosyayı görüntüle @
867d287b
...
@@ -695,6 +695,45 @@ class SessionMiddlewareTests(TestCase):
...
@@ -695,6 +695,45 @@ class SessionMiddlewareTests(TestCase):
# The session is accessed so "Vary: Cookie" should be set.
# The session is accessed so "Vary: Cookie" should be set.
self
.
assertEqual
(
response
[
'Vary'
],
'Cookie'
)
self
.
assertEqual
(
response
[
'Vary'
],
'Cookie'
)
def
test_empty_session_saved
(
self
):
""""
If a session is emptied of data but still has a key, it should still
be updated.
"""
request
=
RequestFactory
()
.
get
(
'/'
)
response
=
HttpResponse
(
'Session test'
)
middleware
=
SessionMiddleware
()
# Set a session key and some data.
middleware
.
process_request
(
request
)
request
.
session
[
'foo'
]
=
'bar'
# Handle the response through the middleware.
response
=
middleware
.
process_response
(
request
,
response
)
self
.
assertEqual
(
tuple
(
request
.
session
.
items
()),
((
'foo'
,
'bar'
),))
# A cookie should be set, along with Vary: Cookie.
self
.
assertIn
(
'Set-Cookie: sessionid=
%
s'
%
request
.
session
.
session_key
,
str
(
response
.
cookies
)
)
self
.
assertEqual
(
response
[
'Vary'
],
'Cookie'
)
# Empty the session data.
del
request
.
session
[
'foo'
]
# Handle the response through the middleware.
response
=
HttpResponse
(
'Session test'
)
response
=
middleware
.
process_response
(
request
,
response
)
self
.
assertEqual
(
dict
(
request
.
session
.
values
()),
{})
session
=
Session
.
objects
.
get
(
session_key
=
request
.
session
.
session_key
)
self
.
assertEqual
(
session
.
get_decoded
(),
{})
# While the session is empty, it hasn't been flushed so a cookie should
# still be set, along with Vary: Cookie.
self
.
assertGreater
(
len
(
request
.
session
.
session_key
),
8
)
self
.
assertIn
(
'Set-Cookie: sessionid=
%
s'
%
request
.
session
.
session_key
,
str
(
response
.
cookies
)
)
self
.
assertEqual
(
response
[
'Vary'
],
'Cookie'
)
# Don't need DB flushing for these tests, so can use unittest.TestCase as base class
# Don't need DB flushing for these tests, so can use unittest.TestCase as base class
class
CookieSessionTests
(
SessionTestsMixin
,
unittest
.
TestCase
):
class
CookieSessionTests
(
SessionTestsMixin
,
unittest
.
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