MCPcopy
hub / github.com/django/django / test_check_constraints

Method test_check_constraints

tests/backends/tests.py:742–765  ·  view source on GitHub ↗

Constraint checks should raise an IntegrityError when bad data is in the DB.

(self)

Source from the content-addressed store, hash-verified

740 transaction.set_rollback(True)
741
742 def test_check_constraints(self):
743 """
744 Constraint checks should raise an IntegrityError when bad data is in
745 the DB.
746 """
747 with transaction.atomic():
748 # Create an Article.
749 Article.objects.create(
750 headline="Test article",
751 pub_date=datetime.datetime(2010, 9, 4),
752 reporter=self.r,
753 )
754 # Retrieve it from the DB
755 a = Article.objects.get(headline="Test article")
756 a.reporter_id = 30
757 with connection.constraint_checks_disabled():
758 a.save()
759 try:
760 connection.check_constraints(table_names=[Article._meta.db_table])
761 except IntegrityError:
762 pass
763 else:
764 self.skipTest("This backend does not support integrity checks.")
765 transaction.set_rollback(True)
766
767 def test_check_constraints_sql_keywords(self):
768 with transaction.atomic():

Callers

nothing calls this directly

Calls 6

set_rollbackMethod · 0.80
createMethod · 0.45
getMethod · 0.45
saveMethod · 0.45
check_constraintsMethod · 0.45

Tested by

no test coverage detected