(self)
| 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): |
nothing calls this directly
no test coverage detected