Fixed #32458 -- Made __repr__() for Index and BaseConstraint subclasses more consistent.

This commit is contained in:
Hannes Ljungberg 2021-02-19 12:16:24 +01:00 committed by Mariusz Felisiak
parent 7c18b22e2f
commit 87acbf0631
8 changed files with 84 additions and 42 deletions

View file

@ -16,6 +16,7 @@ class SimpleIndexesTests(SimpleTestCase):
def test_repr(self):
index = models.Index(fields=['title'])
named_index = models.Index(fields=['title'], name='title_idx')
multi_col_index = models.Index(fields=['title', 'author'])
partial_index = models.Index(fields=['title'], name='long_books_idx', condition=models.Q(pages__gt=400))
covering_index = models.Index(
@ -28,20 +29,43 @@ class SimpleIndexesTests(SimpleTestCase):
name='opclasses_idx',
opclasses=['varchar_pattern_ops', 'text_pattern_ops'],
)
func_index = models.Index(Lower('title'), name='book_func_idx')
self.assertEqual(repr(index), "<Index: fields='title'>")
self.assertEqual(repr(multi_col_index), "<Index: fields='title, author'>")
self.assertEqual(repr(partial_index), "<Index: fields='title' condition=(AND: ('pages__gt', 400))>")
func_index = models.Index(Lower('title'), 'subtitle', name='book_func_idx')
tablespace_index = models.Index(
fields=['title'],
db_tablespace='idx_tbls',
name='book_tablespace_idx',
)
self.assertEqual(repr(index), "<Index: fields=['title']>")
self.assertEqual(
repr(named_index),
"<Index: fields=['title'] name='title_idx'>",
)
self.assertEqual(repr(multi_col_index), "<Index: fields=['title', 'author']>")
self.assertEqual(
repr(partial_index),
"<Index: fields=['title'] name='long_books_idx' "
"condition=(AND: ('pages__gt', 400))>",
)
self.assertEqual(
repr(covering_index),
"<Index: fields='title' include='author, pages'>",
"<Index: fields=['title'] name='include_idx' "
"include=('author', 'pages')>",
)
self.assertEqual(
repr(opclasses_index),
"<Index: fields='headline, body' "
"opclasses='varchar_pattern_ops, text_pattern_ops'>",
"<Index: fields=['headline', 'body'] name='opclasses_idx' "
"opclasses=['varchar_pattern_ops', 'text_pattern_ops']>",
)
self.assertEqual(
repr(func_index),
"<Index: expressions=(Lower(F(title)), F(subtitle)) "
"name='book_func_idx'>",
)
self.assertEqual(
repr(tablespace_index),
"<Index: fields=['title'] name='book_tablespace_idx' "
"db_tablespace='idx_tbls'>",
)
self.assertEqual(repr(func_index), "<Index: expressions='Lower(F(title))'>")
def test_eq(self):
index = models.Index(fields=['title'])