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
5549e89b
Kaydet (Commit)
5549e89b
authored
Eyl 11, 2016
tarafından
Tom Scrace
Kaydeden (comit)
Tim Graham
Kas 09, 2016
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27184 -- Allowed uploading TemporaryFile with the test client.
Thanks Federico Capoano for finishing the patch.
üst
f94ce0d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
1 deletion
+19
-1
client.py
django/test/client.py
+6
-1
tests.py
tests/test_client/tests.py
+7
-0
urls.py
tests/test_client/urls.py
+1
-0
views.py
tests/test_client/views.py
+5
-0
No files found.
django/test/client.py
Dosyayı görüntüle @
5549e89b
...
...
@@ -226,7 +226,12 @@ def encode_multipart(boundary, data):
def
encode_file
(
boundary
,
key
,
file
):
def
to_bytes
(
s
):
return
force_bytes
(
s
,
settings
.
DEFAULT_CHARSET
)
filename
=
os
.
path
.
basename
(
file
.
name
)
if
hasattr
(
file
,
'name'
)
else
''
# file.name might not be a string. For example, it's an int for
# tempfile.TemporaryFile().
file_has_string_name
=
hasattr
(
file
,
'name'
)
and
isinstance
(
file
.
name
,
six
.
string_types
)
filename
=
os
.
path
.
basename
(
file
.
name
)
if
file_has_string_name
else
''
if
hasattr
(
file
,
'content_type'
):
content_type
=
file
.
content_type
elif
filename
:
...
...
tests/test_client/tests.py
Dosyayı görüntüle @
5549e89b
...
...
@@ -22,6 +22,8 @@ rather than the HTML rendered to the end-user.
"""
from
__future__
import
unicode_literals
import
tempfile
from
django.contrib.auth.models
import
User
from
django.core
import
mail
from
django.http
import
HttpResponse
...
...
@@ -714,6 +716,11 @@ class ClientTest(TestCase):
with
self
.
assertRaisesMessage
(
Exception
,
'exception message'
):
self
.
client
.
get
(
'/nesting_exception_view/'
)
def
test_uploading_temp_file
(
self
):
test_file
=
tempfile
.
TemporaryFile
()
response
=
self
.
client
.
post
(
'/upload_view/'
,
data
=
{
'temp_file'
:
test_file
})
self
.
assertEqual
(
response
.
content
,
b
'temp_file'
)
@override_settings
(
MIDDLEWARE
=
[
'django.middleware.csrf.CsrfViewMiddleware'
],
...
...
tests/test_client/urls.py
Dosyayı görüntüle @
5549e89b
...
...
@@ -5,6 +5,7 @@ from django.views.generic import RedirectView
from
.
import
views
urlpatterns
=
[
url
(
r'^upload_view/$'
,
views
.
upload_view
,
name
=
'upload_view'
),
url
(
r'^get_view/$'
,
views
.
get_view
,
name
=
'get_view'
),
url
(
r'^post_view/$'
,
views
.
post_view
),
url
(
r'^trace_view/$'
,
views
.
trace_view
),
...
...
tests/test_client/views.py
Dosyayı görüntüle @
5549e89b
...
...
@@ -324,3 +324,8 @@ def nesting_exception_view(request):
def
django_project_redirect
(
request
):
return
HttpResponseRedirect
(
'https://www.djangoproject.com/'
)
def
upload_view
(
request
):
"""Prints keys of request.FILES to the response."""
return
HttpResponse
(
', '
.
join
(
request
.
FILES
.
keys
()))
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