MCPcopy
hub / github.com/django/django / test_add_db_comment_and_default_charfield

Method test_add_db_comment_and_default_charfield

tests/schema/tests.py:5031–5049  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5029
5030 @skipUnlessDBFeature("supports_comments")
5031 def test_add_db_comment_and_default_charfield(self):
5032 comment = "Custom comment with default"
5033 field = CharField(max_length=255, default="Joe Doe", db_comment=comment)
5034 field.set_attributes_from_name("name_with_comment_default")
5035 with connection.schema_editor() as editor:
5036 editor.create_model(Author)
5037 Author.objects.create(name="Before adding a new field")
5038 editor.add_field(Author, field)
5039
5040 self.assertEqual(
5041 self.get_column_comment(Author._meta.db_table, "name_with_comment_default"),
5042 comment,
5043 )
5044 with connection.cursor() as cursor:
5045 cursor.execute(
5046 f"SELECT name_with_comment_default FROM {Author._meta.db_table};"
5047 )
5048 for row in cursor.fetchall():
5049 self.assertEqual(row[0], "Joe Doe")
5050
5051 @skipUnlessDBFeature("supports_comments")
5052 def test_alter_db_comment(self):

Callers

nothing calls this directly

Calls 9

get_column_commentMethod · 0.95
CharFieldClass · 0.90
schema_editorMethod · 0.80
cursorMethod · 0.80
create_modelMethod · 0.45
createMethod · 0.45
add_fieldMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected