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
7fa1dd8a
Kaydet (Commit)
7fa1dd8a
authored
Agu 07, 2015
tarafından
pscottdevos
Kaydeden (comit)
Tim Graham
Agu 11, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25163 -- Fixed exception handling in nested test client requests.
üst
56ed80ac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
3 deletions
+23
-3
client.py
django/test/client.py
+3
-3
tests.py
tests/test_client/tests.py
+8
-0
urls.py
tests/test_client/urls.py
+1
-0
views.py
tests/test_client/views.py
+11
-0
No files found.
django/test/client.py
Dosyayı görüntüle @
7fa1dd8a
...
...
@@ -442,9 +442,9 @@ class Client(RequestFactory):
signal_uid
=
"template-render-
%
s"
%
id
(
request
)
signals
.
template_rendered
.
connect
(
on_template_render
,
dispatch_uid
=
signal_uid
)
# Capture exceptions created by the handler.
got_request_exception
.
connect
(
self
.
store_exc_info
,
dispatch_uid
=
"request-exception"
)
exception_uid
=
"request-exception-
%
s"
%
id
(
request
)
got_request_exception
.
connect
(
self
.
store_exc_info
,
dispatch_uid
=
exception_uid
)
try
:
try
:
response
=
self
.
handler
(
environ
)
except
TemplateDoesNotExist
as
e
:
...
...
@@ -493,7 +493,7 @@ class Client(RequestFactory):
return
response
finally
:
signals
.
template_rendered
.
disconnect
(
dispatch_uid
=
signal_uid
)
got_request_exception
.
disconnect
(
dispatch_uid
=
"request-exception"
)
got_request_exception
.
disconnect
(
dispatch_uid
=
exception_uid
)
def
get
(
self
,
path
,
data
=
None
,
follow
=
False
,
secure
=
False
,
**
extra
):
"""
...
...
tests/test_client/tests.py
Dosyayı görüntüle @
7fa1dd8a
...
...
@@ -640,6 +640,14 @@ class ClientTest(TestCase):
self
.
assertEqual
(
mail
.
outbox
[
1
]
.
to
[
0
],
'second@example.com'
)
self
.
assertEqual
(
mail
.
outbox
[
1
]
.
to
[
1
],
'third@example.com'
)
def
test_exception_following_nested_client_request
(
self
):
"""
A nested test client request shouldn't clobber exception signals from
the outer client request.
"""
with
self
.
assertRaisesMessage
(
Exception
,
'exception message'
):
self
.
client
.
get
(
'/nesting_exception_view/'
)
@override_settings
(
MIDDLEWARE_CLASSES
=
[
'django.middleware.csrf.CsrfViewMiddleware'
],
...
...
tests/test_client/urls.py
Dosyayı görüntüle @
7fa1dd8a
...
...
@@ -31,6 +31,7 @@ urlpatterns = [
url
(
r'^broken_view/$'
,
views
.
broken_view
),
url
(
r'^mail_sending_view/$'
,
views
.
mail_sending_view
),
url
(
r'^mass_mail_sending_view/$'
,
views
.
mass_mail_sending_view
),
url
(
r'^nesting_exception_view/$'
,
views
.
nesting_exception_view
),
url
(
r'^django_project_redirect/$'
,
views
.
django_project_redirect
),
url
(
r'^accounts/login/$'
,
auth_views
.
login
,
{
'template_name'
:
'login.html'
}),
...
...
tests/test_client/views.py
Dosyayı görüntüle @
7fa1dd8a
...
...
@@ -11,6 +11,7 @@ from django.http import (
)
from
django.shortcuts
import
render_to_response
from
django.template
import
Context
,
Template
from
django.test
import
Client
from
django.utils.decorators
import
method_decorator
from
django.utils.six.moves.urllib.parse
import
urlencode
...
...
@@ -309,5 +310,15 @@ def mass_mail_sending_view(request):
return
HttpResponse
(
"Mail sent"
)
def
nesting_exception_view
(
request
):
"""
A view that uses a nested client to call another view and then raises an
exception.
"""
client
=
Client
()
client
.
get
(
'/get_view/'
)
raise
Exception
(
'exception message'
)
def
django_project_redirect
(
request
):
return
HttpResponseRedirect
(
'https://www.djangoproject.com/'
)
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