Python django.utils.deprecation.RemovedInDjango30Warning() Examples

The following are 16 code examples of django.utils.deprecation.RemovedInDjango30Warning(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.utils.deprecation , or try the search function .
Example #1
Source File: test_has_add_permission_obj_deprecation.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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) 
Example #2
Source File: test_static_deprecation.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #3
Source File: test_has_add_permission_obj_deprecation.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: test_static_deprecation.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
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 
Example #5
Source File: request.py    From bioforum with MIT License 5 votes vote down vote up
def xreadlines(self):
        warnings.warn(
            'HttpRequest.xreadlines() is deprecated in favor of iterating the '
            'request.', RemovedInDjango30Warning, stacklevel=2,
        )
        yield from self 
Example #6
Source File: request.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def xreadlines(self):
        warnings.warn(
            'HttpRequest.xreadlines() is deprecated in favor of iterating the '
            'request.', RemovedInDjango30Warning, stacklevel=2,
        )
        yield from self 
Example #7
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #8
Source File: test_default_content_type.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_override_settings_warning(self):
        with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
            with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
                pass 
Example #9
Source File: test_default_content_type.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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'] 
Example #10
Source File: test_templatetag_deprecation.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #11
Source File: test_templatetag_deprecation.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #12
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #13
Source File: test_default_content_type.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_override_settings_warning(self):
        with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
            with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
                pass 
Example #14
Source File: test_default_content_type.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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'] 
Example #15
Source File: test_deprecated.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #16
Source File: conftest.py    From micromasters with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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()