MCPcopy
hub / github.com/django/django / test_name_auto_generation

Method test_name_auto_generation

tests/model_indexes/tests.py:176–198  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

174 models.Index(fields=["field"], include=["other"])
175
176 def test_name_auto_generation(self):
177 index = models.Index(fields=["author"])
178 index.set_name_with_model(Book)
179 self.assertEqual(index.name, "model_index_author_0f5565_idx")
180
181 # '-' for DESC columns should be accounted for in the index name.
182 index = models.Index(fields=["-author"])
183 index.set_name_with_model(Book)
184 self.assertEqual(index.name, "model_index_author_708765_idx")
185
186 # fields may be truncated in the name. db_column is used for naming.
187 long_field_index = models.Index(fields=["pages"])
188 long_field_index.set_name_with_model(Book)
189 self.assertEqual(long_field_index.name, "model_index_page_co_69235a_idx")
190
191 # suffix can't be longer than 3 characters.
192 long_field_index.suffix = "suff"
193 msg = (
194 "Index too long for multiple database support. Is self.suffix "
195 "longer than 3 characters?"
196 )
197 with self.assertRaisesMessage(ValueError, msg):
198 long_field_index.set_name_with_model(Book)
199
200 @isolate_apps("model_indexes")
201 def test_name_auto_generation_with_quoted_db_table(self):

Callers

nothing calls this directly

Calls 2

set_name_with_modelMethod · 0.95
assertRaisesMessageMethod · 0.80

Tested by

no test coverage detected