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
bf743a4d
Kaydet (Commit)
bf743a4d
authored
Haz 06, 2014
tarafından
Greg Chapple
Kaydeden (comit)
Tim Graham
Haz 13, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #16087 -- Added ResolverMatch instance to test client response.
Thanks mrmachine for the suggestion.
üst
2d425116
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
4 deletions
+54
-4
client.py
django/test/client.py
+6
-1
1.8.txt
docs/releases/1.8.txt
+5
-2
tools.txt
docs/topics/testing/tools.txt
+19
-0
tests.py
tests/test_client/tests.py
+23
-0
urls.py
tests/test_client/urls.py
+1
-1
No files found.
django/test/client.py
Dosyayı görüntüle @
bf743a4d
...
...
@@ -10,6 +10,7 @@ from io import BytesIO
from
django.apps
import
apps
from
django.conf
import
settings
from
django.core
import
urlresolvers
from
django.core.handlers.base
import
BaseHandler
from
django.core.handlers.wsgi
import
WSGIRequest
from
django.core.signals
import
(
request_started
,
request_finished
,
...
...
@@ -18,7 +19,7 @@ from django.db import close_old_connections
from
django.http
import
SimpleCookie
,
HttpRequest
,
QueryDict
from
django.template
import
TemplateDoesNotExist
from
django.test
import
signals
from
django.utils.functional
import
curry
from
django.utils.functional
import
curry
,
SimpleLazyObject
from
django.utils.encoding
import
force_bytes
,
force_str
from
django.utils.http
import
urlencode
from
django.utils.itercompat
import
is_iterable
...
...
@@ -449,6 +450,10 @@ class Client(RequestFactory):
response
.
templates
=
data
.
get
(
"templates"
,
[])
response
.
context
=
data
.
get
(
"context"
)
# Attach the ResolverMatch instance to the response
response
.
resolver_match
=
SimpleLazyObject
(
lambda
:
urlresolvers
.
resolve
(
request
[
'PATH_INFO'
]))
# Flatten a single context. Not really necessary anymore thanks to
# the __getattr__ flattening in ContextList, but has some edge-case
# backwards-compatibility implications.
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
bf743a4d
...
...
@@ -214,8 +214,11 @@ Tests
* The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
allows you to test that two JSON fragments are not equal.
* Added the ability to preserve the test database by adding the :djadminopt:`--keepdb`
flag.
* Added the ability to preserve the test database by adding the
:djadminopt:`--keepdb` flag.
* Added the :attr:`~django.test.Response.resolver_match` attribute to test
client responses.
Validators
^^^^^^^^^^
...
...
docs/topics/testing/tools.txt
Dosyayı görüntüle @
bf743a4d
...
...
@@ -432,6 +432,25 @@ Specifically, a ``Response`` object has the following attributes:
loaded from a file. (The name is a string such as
``'admin/index.html'``.)
.. attribute:: resolver_match
.. versionadded:: 1.8
An instance of :class:`~django.core.urlresolvers.ResolverMatch` for the
response. You can use the
:attr:`~django.core.urlresolvers.ResolverMatch.func` attribute, for
example, to verify the view that served the response::
# my_view here is a function based view
self.assertEqual(response.resolver_match.func, my_view)
# class based views need to be compared by name, as the functions
# generated by as_view() won't be equal
self.assertEqual(response.resolver_match.func.__name__, MyView.as_view().__name__)
If the given URL is not found, accessing this attribute will raise a
:exc:`~django.core.urlresolvers.Resolver404` exception.
You can also use dictionary syntax on the response object to query the value
of any settings in the HTTP headers. For example, you could determine the
content type of a response using ``response['Content-Type']``.
...
...
tests/test_client/tests.py
Dosyayı görüntüle @
bf743a4d
...
...
@@ -99,6 +99,29 @@ class ClientTest(TestCase):
self
.
assertIn
(
key
,
response
.
wsgi_request
.
environ
)
self
.
assertEqual
(
response
.
wsgi_request
.
environ
[
key
],
value
)
def
test_response_resolver_match
(
self
):
"""
The response contains a ResolverMatch instance.
"""
response
=
self
.
client
.
get
(
'/header_view/'
)
self
.
assertTrue
(
hasattr
(
response
,
'resolver_match'
))
def
test_response_resolver_match_redirect_follow
(
self
):
"""
The response ResolverMatch instance contains the correct
information when following redirects.
"""
response
=
self
.
client
.
get
(
'/redirect_view/'
,
follow
=
True
)
self
.
assertEqual
(
response
.
resolver_match
.
url_name
,
'get_view'
)
def
test_response_resolver_match_regular_view
(
self
):
"""
The response ResolverMatch instance contains the correct
information when accessing a regular view.
"""
response
=
self
.
client
.
get
(
'/get_view/'
)
self
.
assertEqual
(
response
.
resolver_match
.
url_name
,
'get_view'
)
def
test_raw_post
(
self
):
"POST raw data (with a content type) to a view"
test_doc
=
"""<?xml version="1.0" encoding="utf-8"?><library><book><title>Blink</title><author>Malcolm Gladwell</author></book></library>"""
...
...
tests/test_client/urls.py
Dosyayı görüntüle @
bf743a4d
...
...
@@ -5,7 +5,7 @@ from . import views
urlpatterns
=
[
url
(
r'^get_view/$'
,
views
.
get_view
),
url
(
r'^get_view/$'
,
views
.
get_view
,
name
=
'get_view'
),
url
(
r'^post_view/$'
,
views
.
post_view
),
url
(
r'^header_view/$'
,
views
.
view_with_header
),
url
(
r'^raw_post_view/$'
,
views
.
raw_post_view
),
...
...
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