diff options
| author | Adrian Torres <atorresj@redhat.com> | 2022-11-10 19:31:31 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-12-28 12:31:04 +0100 |
| commit | 7eee1dca420ee7c4451d24cd32fa08aed0dcbb36 (patch) | |
| tree | f643059561e9699cc961845f63faf0a3664ff5d0 /tests | |
| parent | 78f163a4fb3937aca2e71786fbdd51a0ef39629e (diff) | |
Fixed #14094 -- Added support for unlimited CharField on PostgreSQL.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_docs/test_views.py | 10 | ||||
| -rw-r--r-- | tests/inspectdb/models.py | 7 | ||||
| -rw-r--r-- | tests/inspectdb/tests.py | 7 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_ordinary_fields.py | 10 | ||||
| -rw-r--r-- | tests/postgres_tests/test_array.py | 8 |
5 files changed, 34 insertions, 8 deletions
diff --git a/tests/admin_docs/test_views.py b/tests/admin_docs/test_views.py index d85f401855..29bbe40310 100644 --- a/tests/admin_docs/test_views.py +++ b/tests/admin_docs/test_views.py @@ -447,6 +447,16 @@ class TestFieldType(unittest.TestCase): "Boolean (Either True or False)", ) + def test_char_fields(self): + self.assertEqual( + views.get_readable_field_data_type(fields.CharField(max_length=255)), + "String (up to 255)", + ) + self.assertEqual( + views.get_readable_field_data_type(fields.CharField()), + "String (unlimited)", + ) + def test_custom_fields(self): self.assertEqual( views.get_readable_field_data_type(CustomField()), "A custom field type" diff --git a/tests/inspectdb/models.py b/tests/inspectdb/models.py index 5db4d3bc73..9e6871ce46 100644 --- a/tests/inspectdb/models.py +++ b/tests/inspectdb/models.py @@ -106,6 +106,13 @@ class TextFieldDbCollation(models.Model): required_db_features = {"supports_collation_on_textfield"} +class CharFieldUnlimited(models.Model): + char_field = models.CharField(max_length=None) + + class Meta: + required_db_features = {"supports_unlimited_charfield"} + + class UniqueTogether(models.Model): field1 = models.IntegerField() field2 = models.CharField(max_length=10) diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 2f26814625..ad929fd9bc 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -184,6 +184,13 @@ class InspectDBTestCase(TestCase): output, ) + @skipUnlessDBFeature("supports_unlimited_charfield") + def test_char_field_unlimited(self): + out = StringIO() + call_command("inspectdb", "inspectdb_charfieldunlimited", stdout=out) + output = out.getvalue() + self.assertIn("char_field = models.CharField()", output) + def test_number_field_types(self): """Test introspection of various Django field types""" assertFieldType = self.make_field_type_asserter() diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 4e07c95956..4e37c48286 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -112,16 +112,18 @@ class CharFieldTests(TestCase): field = models.CharField() field = Model._meta.get_field("field") - self.assertEqual( - field.check(), - [ + expected = ( + [] + if connection.features.supports_unlimited_charfield + else [ Error( "CharFields must define a 'max_length' attribute.", obj=field, id="fields.E120", ), - ], + ] ) + self.assertEqual(field.check(), expected) def test_negative_max_length(self): class Model(models.Model): diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index 86e9d00b41..4808f88689 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -776,12 +776,12 @@ class TestOtherTypesExactQuerying(PostgreSQLTestCase): class TestChecks(PostgreSQLSimpleTestCase): def test_field_checks(self): class MyModel(PostgreSQLModel): - field = ArrayField(models.CharField()) + field = ArrayField(models.CharField(max_length=-1)) model = MyModel() errors = model.check() self.assertEqual(len(errors), 1) - # The inner CharField is missing a max_length. + # The inner CharField has a non-positive max_length. self.assertEqual(errors[0].id, "postgres.E001") self.assertIn("max_length", errors[0].msg) @@ -837,12 +837,12 @@ class TestChecks(PostgreSQLSimpleTestCase): """ class MyModel(PostgreSQLModel): - field = ArrayField(ArrayField(models.CharField())) + field = ArrayField(ArrayField(models.CharField(max_length=-1))) model = MyModel() errors = model.check() self.assertEqual(len(errors), 1) - # The inner CharField is missing a max_length. + # The inner CharField has a non-positive max_length. self.assertEqual(errors[0].id, "postgres.E001") self.assertIn("max_length", errors[0].msg) |
