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
fbc7e413
Kaydet (Commit)
fbc7e413
authored
Ara 05, 2018
tarafından
François Freitag
Kaydeden (comit)
Tim Graham
Ara 05, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Tested exception messages in generic_views tests.
üst
196b420f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
test_base.py
tests/generic_views/test_base.py
+24
-10
No files found.
tests/generic_views/test_base.py
Dosyayı görüntüle @
fbc7e413
import
time
import
unittest
from
django.core.exceptions
import
ImproperlyConfigured
from
django.http
import
HttpResponse
...
...
@@ -65,7 +64,7 @@ class InstanceView(View):
return
self
class
ViewTest
(
unittest
.
TestCase
):
class
ViewTest
(
Simple
TestCase
):
rf
=
RequestFactory
()
def
_assert_simple
(
self
,
response
):
...
...
@@ -76,14 +75,16 @@ class ViewTest(unittest.TestCase):
"""
A view can't be accidentally instantiated before deployment
"""
with
self
.
assertRaises
(
AttributeError
):
msg
=
'This method is available only on the class, not on instances.'
with
self
.
assertRaisesMessage
(
AttributeError
,
msg
):
SimpleView
(
key
=
'value'
)
.
as_view
()
def
test_no_init_args
(
self
):
"""
A view can't be accidentally instantiated before deployment
"""
with
self
.
assertRaises
(
TypeError
):
msg
=
'as_view() takes 1 positional argument but 2 were given'
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
SimpleView
.
as_view
(
'value'
)
def
test_pathological_http_method
(
self
):
...
...
@@ -134,15 +135,24 @@ class ViewTest(unittest.TestCase):
View arguments must be predefined on the class and can't
be named like a HTTP method.
"""
msg
=
(
"You tried to pass in the
%
s method name as a keyword argument "
"to SimpleView(). Don't do that."
)
# Check each of the allowed method names
for
method
in
SimpleView
.
http_method_names
:
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
Message
(
TypeError
,
msg
%
method
):
SimpleView
.
as_view
(
**
{
method
:
'value'
})
# Check the case view argument is ok if predefined on the class...
CustomizableView
.
as_view
(
parameter
=
"value"
)
# ...but raises errors otherwise.
with
self
.
assertRaises
(
TypeError
):
msg
=
(
"CustomizableView() received an invalid keyword 'foobar'. "
"as_view only accepts arguments that are already attributes of "
"the class."
)
with
self
.
assertRaisesMessage
(
TypeError
,
msg
):
CustomizableView
.
as_view
(
foobar
=
"value"
)
def
test_calling_more_than_once
(
self
):
...
...
@@ -466,7 +476,7 @@ class RedirectViewTest(SimpleTestCase):
self
.
assertEqual
(
response
.
status_code
,
410
)
class
GetContextDataTest
(
unittest
.
TestCase
):
class
GetContextDataTest
(
Simple
TestCase
):
def
test_get_context_data_super
(
self
):
test_view
=
views
.
CustomContextView
()
...
...
@@ -495,7 +505,7 @@ class GetContextDataTest(unittest.TestCase):
self
.
assertEqual
(
context
[
'object'
],
test_view
.
object
)
class
UseMultipleObjectMixinTest
(
unittest
.
TestCase
):
class
UseMultipleObjectMixinTest
(
Simple
TestCase
):
rf
=
RequestFactory
()
def
test_use_queryset_from_view
(
self
):
...
...
@@ -515,7 +525,7 @@ class UseMultipleObjectMixinTest(unittest.TestCase):
self
.
assertEqual
(
context
[
'object_list'
],
queryset
)
class
SingleObjectTemplateResponseMixinTest
(
unittest
.
TestCase
):
class
SingleObjectTemplateResponseMixinTest
(
Simple
TestCase
):
def
test_template_mixin_without_template
(
self
):
"""
...
...
@@ -524,5 +534,9 @@ class SingleObjectTemplateResponseMixinTest(unittest.TestCase):
TemplateDoesNotExist.
"""
view
=
views
.
TemplateResponseWithoutTemplate
()
with
self
.
assertRaises
(
ImproperlyConfigured
):
msg
=
(
"TemplateResponseMixin requires either a definition of "
"'template_name' or an implementation of 'get_template_names()'"
)
with
self
.
assertRaisesMessage
(
ImproperlyConfigured
,
msg
):
view
.
get_template_names
()
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