Simplified tests for PostgreSQL constraints.

This commit is contained in:
Mariusz Felisiak 2019-07-16 16:56:44 +02:00 committed by GitHub
parent ad4e83a6d1
commit cf79f92abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 9 deletions

View File

@ -29,9 +29,7 @@ class SchemaTests(PostgreSQLTestCase):
) )
with connection.schema_editor() as editor: with connection.schema_editor() as editor:
editor.add_constraint(RangesModel, constraint) editor.add_constraint(RangesModel, constraint)
with connection.cursor() as cursor: self.assertIn(constraint_name, self.get_constraints(RangesModel._meta.db_table))
constraints = connection.introspection.get_constraints(cursor, RangesModel._meta.db_table)
self.assertIn(constraint_name, constraints)
with self.assertRaises(IntegrityError), transaction.atomic(): with self.assertRaises(IntegrityError), transaction.atomic():
RangesModel.objects.create(ints=(20, 50)) RangesModel.objects.create(ints=(20, 50))
RangesModel.objects.create(ints=(10, 30)) RangesModel.objects.create(ints=(10, 30))
@ -45,9 +43,7 @@ class SchemaTests(PostgreSQLTestCase):
) )
with connection.schema_editor() as editor: with connection.schema_editor() as editor:
editor.add_constraint(RangesModel, constraint) editor.add_constraint(RangesModel, constraint)
with connection.cursor() as cursor: self.assertIn(constraint_name, self.get_constraints(RangesModel._meta.db_table))
constraints = connection.introspection.get_constraints(cursor, RangesModel._meta.db_table)
self.assertIn(constraint_name, constraints)
date_1 = datetime.date(2016, 1, 1) date_1 = datetime.date(2016, 1, 1)
date_2 = datetime.date(2016, 1, 4) date_2 = datetime.date(2016, 1, 4)
with self.assertRaises(IntegrityError), transaction.atomic(): with self.assertRaises(IntegrityError), transaction.atomic():
@ -69,9 +65,7 @@ class SchemaTests(PostgreSQLTestCase):
) )
with connection.schema_editor() as editor: with connection.schema_editor() as editor:
editor.add_constraint(RangesModel, constraint) editor.add_constraint(RangesModel, constraint)
with connection.cursor() as cursor: self.assertIn(constraint_name, self.get_constraints(RangesModel._meta.db_table))
constraints = connection.introspection.get_constraints(cursor, RangesModel._meta.db_table)
self.assertIn(constraint_name, constraints)
datetime_1 = datetime.datetime(2016, 1, 1) datetime_1 = datetime.datetime(2016, 1, 1)
datetime_2 = datetime.datetime(2016, 1, 2, 12) datetime_2 = datetime.datetime(2016, 1, 2, 12)
with self.assertRaises(IntegrityError), transaction.atomic(): with self.assertRaises(IntegrityError), transaction.atomic():