diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/invalid_models_tests/test_deprecated_fields.py | 21 | ||||
-rw-r--r-- | tests/postgres_tests/test_json_deprecation.py | 18 |
2 files changed, 20 insertions, 19 deletions
diff --git a/tests/invalid_models_tests/test_deprecated_fields.py b/tests/invalid_models_tests/test_deprecated_fields.py index e240f20ba5..a3ee618ce4 100644 --- a/tests/invalid_models_tests/test_deprecated_fields.py +++ b/tests/invalid_models_tests/test_deprecated_fields.py @@ -1,5 +1,7 @@ +from unittest import skipUnless + from django.core import checks -from django.db import models +from django.db import connection, models from django.test import SimpleTestCase from django.test.utils import isolate_apps @@ -52,3 +54,20 @@ class DeprecatedFieldsTests(SimpleTestCase): id='fields.E903', ), ]) + + @skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific SQL') + def test_postgres_jsonfield_deprecated(self): + from django.contrib.postgres.fields import JSONField + + class PostgresJSONFieldModel(models.Model): + field = JSONField() + + self.assertEqual(PostgresJSONFieldModel.check(), [ + checks.Error( + 'django.contrib.postgres.fields.JSONField is removed except ' + 'for support in historical migrations.', + hint='Use django.db.models.JSONField instead.', + obj=PostgresJSONFieldModel._meta.get_field('field'), + id='fields.E904', + ), + ]) diff --git a/tests/postgres_tests/test_json_deprecation.py b/tests/postgres_tests/test_json_deprecation.py index 69dcce3781..7c78c6a864 100644 --- a/tests/postgres_tests/test_json_deprecation.py +++ b/tests/postgres_tests/test_json_deprecation.py @@ -1,35 +1,17 @@ try: from django.contrib.postgres import forms - from django.contrib.postgres.fields import JSONField from django.contrib.postgres.fields.jsonb import ( KeyTextTransform, KeyTransform, ) except ImportError: pass -from django.core.checks import Warning as DjangoWarning from django.utils.deprecation import RemovedInDjango40Warning from . import PostgreSQLSimpleTestCase -from .models import PostgreSQLModel class DeprecationTests(PostgreSQLSimpleTestCase): - def test_model_field_deprecation_message(self): - class PostgreSQLJSONModel(PostgreSQLModel): - field = JSONField() - - self.assertEqual(PostgreSQLJSONModel().check(), [ - DjangoWarning( - 'django.contrib.postgres.fields.JSONField is deprecated. ' - 'Support for it (except in historical migrations) will be ' - 'removed in Django 4.0.', - hint='Use django.db.models.JSONField instead.', - obj=PostgreSQLJSONModel._meta.get_field('field'), - id='fields.W904', - ), - ]) - def test_form_field_deprecation_message(self): msg = ( 'django.contrib.postgres.forms.JSONField is deprecated in favor ' |