summaryrefslogtreecommitdiff
path: root/tests/introspection
diff options
context:
space:
mode:
authorkimsoungryoul <kimsoungryoul@gmail.com>2022-10-16 14:59:39 +0900
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-28 06:28:07 +0100
commit78f163a4fb3937aca2e71786fbdd51a0ef39629e (patch)
tree7e61c2f8d96b9dab60e317d3483460064327d701 /tests/introspection
parent68ef274bc505cd44f305c03cbf84cf08826200a8 (diff)
downloaddjango-78f163a4fb3937aca2e71786fbdd51a0ef39629e.tar.gz
Fixed #18468 -- Added support for comments on columns and tables.
Thanks Jared Chung, Tom Carrick, David Smith, Nick Pope, and Mariusz Felisiak for reviews. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
Diffstat (limited to 'tests/introspection')
-rw-r--r--tests/introspection/models.py8
-rw-r--r--tests/introspection/tests.py21
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/introspection/models.py b/tests/introspection/models.py
index 31c1b0de80..d31eb0cbfa 100644
--- a/tests/introspection/models.py
+++ b/tests/introspection/models.py
@@ -102,3 +102,11 @@ class UniqueConstraintConditionModel(models.Model):
condition=models.Q(color__isnull=True),
),
]
+
+
+class DbCommentModel(models.Model):
+ name = models.CharField(max_length=15, db_comment="'Name' column comment")
+
+ class Meta:
+ db_table_comment = "Custom table comment"
+ required_db_features = {"supports_comments"}
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 459a405932..a283aa0769 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -9,6 +9,7 @@ from .models import (
City,
Comment,
Country,
+ DbCommentModel,
District,
Reporter,
UniqueConstraintConditionModel,
@@ -179,6 +180,26 @@ class IntrospectionTests(TransactionTestCase):
[connection.introspection.get_field_type(r[1], r) for r in desc],
)
+ @skipUnlessDBFeature("supports_comments")
+ def test_db_comments(self):
+ with connection.cursor() as cursor:
+ desc = connection.introspection.get_table_description(
+ cursor, DbCommentModel._meta.db_table
+ )
+ table_list = connection.introspection.get_table_list(cursor)
+ self.assertEqual(
+ ["'Name' column comment"],
+ [field.comment for field in desc if field.name == "name"],
+ )
+ self.assertEqual(
+ ["Custom table comment"],
+ [
+ table.comment
+ for table in table_list
+ if table.name == "introspection_dbcommentmodel"
+ ],
+ )
+
# Regression test for #9991 - 'real' types in postgres
@skipUnlessDBFeature("has_real_datatype")
def test_postgresql_real_type(self):