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
296919e7
Kaydet (Commit)
296919e7
authored
Haz 10, 2015
tarafından
Moritz Sichert
Kaydeden (comit)
Tim Graham
Haz 12, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24965 -- Made LiveServerTestCase.live_server_url accessible from class
üst
e93e0c03
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
5 deletions
+64
-5
decorators.py
django/utils/decorators.py
+12
-0
tools.txt
docs/topics/testing/tools.txt
+6
-0
tests.py
tests/servers/tests.py
+7
-4
test_decorators.py
tests/utils_tests/test_decorators.py
+39
-1
No files found.
django/utils/decorators.py
Dosyayı görüntüle @
296919e7
...
...
@@ -144,3 +144,15 @@ if ContextDecorator is None:
with
self
:
return
func
(
*
args
,
**
kwargs
)
return
inner
class
classproperty
(
object
):
def
__init__
(
self
,
method
=
None
):
self
.
fget
=
method
def
__get__
(
self
,
instance
,
owner
):
return
self
.
fget
(
owner
)
def
getter
(
self
,
method
):
self
.
fget
=
method
return
self
docs/topics/testing/tools.txt
Dosyayı görüntüle @
296919e7
...
...
@@ -789,6 +789,12 @@ via the :djadminopt:`--liveserver` option, for example:
$ ./manage.py test --liveserver=localhost:8082
.. versionchanged:: 1.9
In older versions ``live_server_url`` could only be accessed from an
instance. It now is a class property and can be accessed from class methods
like ``setUpClass()``.
Another way of changing the default server address is by setting the
`DJANGO_LIVE_TEST_SERVER_ADDRESS` environment variable somewhere in your
code (for example, in a :ref:`custom test runner<topics-testing-test_runner>`)::
...
...
tests/servers/tests.py
Dosyayı görüntüle @
296919e7
...
...
@@ -11,6 +11,7 @@ from django.core.exceptions import ImproperlyConfigured
from
django.test
import
LiveServerTestCase
,
override_settings
from
django.utils._os
import
upath
from
django.utils.http
import
urlencode
from
django.utils.six
import
text_type
from
django.utils.six.moves.urllib.error
import
HTTPError
from
django.utils.six.moves.urllib.request
import
urlopen
...
...
@@ -71,6 +72,9 @@ class LiveServerAddress(LiveServerBase):
else
:
del
os
.
environ
[
'DJANGO_LIVE_TEST_SERVER_ADDRESS'
]
# put it in a list to prevent descriptor lookups in test
cls
.
live_server_url_test
=
[
cls
.
live_server_url
]
@classmethod
def
tearDownClass
(
cls
):
# skip it, as setUpClass doesn't call its parent either
...
...
@@ -87,10 +91,9 @@ class LiveServerAddress(LiveServerBase):
finally
:
super
(
LiveServerAddress
,
cls
)
.
tearDownClass
()
def
test_test_test
(
self
):
# Intentionally empty method so that the test is picked up by the
# test runner and the overridden setUpClass() method is executed.
pass
def
test_live_server_url_is_class_property
(
self
):
self
.
assertIsInstance
(
self
.
live_server_url_test
[
0
],
text_type
)
self
.
assertEqual
(
self
.
live_server_url_test
[
0
],
self
.
live_server_url
)
class
LiveServerViews
(
LiveServerBase
):
...
...
tests/utils_tests/test_decorators.py
Dosyayı görüntüle @
296919e7
...
...
@@ -2,7 +2,7 @@ from django.http import HttpResponse
from
django.template
import
engines
from
django.template.response
import
TemplateResponse
from
django.test
import
RequestFactory
,
SimpleTestCase
from
django.utils.decorators
import
decorator_from_middleware
from
django.utils.decorators
import
classproperty
,
decorator_from_middleware
class
ProcessViewMiddleware
(
object
):
...
...
@@ -107,3 +107,41 @@ class DecoratorFromMiddlewareTests(SimpleTestCase):
self
.
assertTrue
(
getattr
(
request
,
'process_response_reached'
,
False
))
# Check that process_response saw the rendered content
self
.
assertEqual
(
request
.
process_response_content
,
b
"Hello world"
)
class
ClassPropertyTest
(
SimpleTestCase
):
def
test_getter
(
self
):
class
Foo
(
object
):
foo_attr
=
123
def
__init__
(
self
):
self
.
foo_attr
=
456
@classproperty
def
foo
(
cls
):
return
cls
.
foo_attr
class
Bar
(
object
):
bar
=
classproperty
()
@bar.getter
def
bar
(
cls
):
return
123
self
.
assertEqual
(
Foo
.
foo
,
123
)
self
.
assertEqual
(
Foo
()
.
foo
,
123
)
self
.
assertEqual
(
Bar
.
bar
,
123
)
self
.
assertEqual
(
Bar
()
.
bar
,
123
)
def
test_override_getter
(
self
):
class
Foo
(
object
):
@classproperty
def
foo
(
cls
):
return
123
@foo.getter
def
foo
(
cls
):
return
456
self
.
assertEqual
(
Foo
.
foo
,
456
)
self
.
assertEqual
(
Foo
()
.
foo
,
456
)
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