本文整理匯總了Python中django.utils.deprecation.RemovedInDjango30Warning方法的典型用法代碼示例。如果您正苦於以下問題:Python deprecation.RemovedInDjango30Warning方法的具體用法?Python deprecation.RemovedInDjango30Warning怎麽用?Python deprecation.RemovedInDjango30Warning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.deprecation
的用法示例。
在下文中一共展示了deprecation.RemovedInDjango30Warning方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_inline_admin_warning
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_inline_admin_warning(self):
class SongInlineAdmin(TabularInline):
model = Song
def has_add_permission(self, request):
return super().has_add_permission(request)
class BandAdmin(ModelAdmin):
inlines = [SongInlineAdmin]
msg = (
"Update SongInlineAdmin.has_add_permission() to accept a "
"positional `obj` argument."
)
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
self.assertIsValid(BandAdmin, Band)
示例2: test
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test(self):
"""
admin_static.static points to the collectstatic version
(as django.contrib.collectstatic is in INSTALLED_APPS).
"""
msg = (
'{% load admin_static %} is deprecated in favor of '
'{% load static %}.'
)
old_url = staticfiles_storage.base_url
staticfiles_storage.base_url = '/test/'
try:
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
url = static('path')
self.assertEqual(url, '/test/path')
finally:
staticfiles_storage.base_url = old_url
示例3: xreadlines
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def xreadlines(self):
warnings.warn(
'HttpRequest.xreadlines() is deprecated in favor of iterating the '
'request.', RemovedInDjango30Warning, stacklevel=2,
)
yield from self
示例4: test_field_name_kwarg_deprecation
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_field_name_kwarg_deprecation(self):
Person.objects.create(name='Deprecator', birthday=datetime(1950, 1, 1))
msg = (
'The field_name keyword argument to earliest() and latest() '
'is deprecated in favor of passing positional arguments.'
)
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
Person.objects.latest(field_name='birthday')
示例5: test_override_settings_warning
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_override_settings_warning(self):
with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
pass
示例6: test_settings_init_warning
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_settings_init_warning(self):
settings_module = ModuleType('fake_settings_module')
settings_module.DEFAULT_CONTENT_TYPE = 'text/xml'
settings_module.SECRET_KEY = 'abc'
sys.modules['fake_settings_module'] = settings_module
try:
with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
Settings('fake_settings_module')
finally:
del sys.modules['fake_settings_module']
示例7: test_templatetag_deprecated
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_templatetag_deprecated(self):
msg = '{% load staticfiles %} is deprecated in favor of {% load static %}.'
template = "{% load staticfiles %}{% static 'main.js' %}"
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
template = Template(template)
rendered = template.render(Context())
self.assertEqual(rendered, 'https://example.com/assets/main.js')
示例8: test_static_deprecated
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_static_deprecated(self):
msg = (
'django.contrib.staticfiles.templatetags.static() is deprecated in '
'favor of django.templatetags.static.static().'
)
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
url = static('main.js')
self.assertEqual(url, 'https://example.com/assets/main.js')
示例9: test_deprecation
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def test_deprecation(self):
msg = (
'Remove the context parameter from CashFieldDeprecated.from_db_value(). '
'Support for it will be removed in Django 3.0.'
)
CashModelDeprecated.objects.create(cash='12.50')
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
instance = CashModelDeprecated.objects.get()
self.assertIsInstance(instance.cash, Cash)
示例10: warnings_as_errors
# 需要導入模塊: from django.utils import deprecation [as 別名]
# 或者: from django.utils.deprecation import RemovedInDjango30Warning [as 別名]
def warnings_as_errors():
"""
Convert warnings to errors. This should only affect unit tests, letting pylint and other plugins
raise DeprecationWarnings without erroring.
"""
try:
warnings.resetwarnings()
warnings.simplefilter('error')
# For celery
warnings.simplefilter('ignore', category=ImportWarning)
warnings.filterwarnings(
"ignore",
message="'async' and 'await' will become reserved keywords in Python 3.7",
category=DeprecationWarning,
)
warnings.filterwarnings(
"ignore",
message=(
"Using or importing the ABCs from 'collections' instead of "
"from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working"
),
category=DeprecationWarning
)
warnings.filterwarnings(
"ignore",
message=(
"Using or importing the ABCs from 'collections' instead of "
"from 'collections.abc' is deprecated, and in 3.8 it will stop working"
),
category=DeprecationWarning
)
# For compatibility modules in various libraries
warnings.filterwarnings(
"ignore",
module=".*(compat|permission_tags).*",
)
# For pysftp
warnings.filterwarnings(
"ignore",
category=UserWarning,
message='Failed to load HostKeys',
)
# For Django 3.0 compatibility, which we don't care about yet
warnings.filterwarnings("ignore", category=RemovedInDjango30Warning)
yield
finally:
warnings.resetwarnings()