Constraint checks should raise an IntegrityError when bad data is in the DB.
(self)
| 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(): |
nothing calls this directly
no test coverage detected