1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #25274 --- Made inspectdb handle renamed fields in unique_together.

This commit is contained in:
Jacek Bzdak
2015-11-06 17:29:23 +01:00
committed by Tim Graham
parent ec202eff84
commit 2cb50f935a
4 changed files with 27 additions and 9 deletions

View File

@@ -234,10 +234,18 @@ class InspectDBTestCase(TestCase):
table_name_filter=lambda tn: tn.startswith('inspectdb_uniquetogether'),
stdout=out)
output = out.getvalue()
self.assertIn(
" unique_together = (('field1', 'field2'),)", output,
msg='inspectdb should generate unique_together.'
)
unique_re = re.compile(r'.*unique_together = \((.+),\).*')
unique_together_match = re.findall(unique_re, output)
# There should be one unique_together tuple.
self.assertEqual(len(unique_together_match), 1)
fields = unique_together_match[0]
# Fields with db_column = field name.
self.assertIn("('field1', 'field2')", fields)
# Fields from columns whose names are Python keywords.
self.assertIn("('field1', 'field2')", fields)
# Fields whose names normalize to the same Python field name and hence
# are given an integer suffix.
self.assertIn("('non_unique_column', 'non_unique_column_0')", fields)
@skipUnless(connection.vendor == 'sqlite',
"Only patched sqlite's DatabaseIntrospection.data_types_reverse for this test")