예제 #1
0
 def test_manually_managed_with_using(self):
     """
     The commit_manually function also works with a using argument.
     """
     with self.assertRaises(transaction.TransactionManagementError):
         with transaction.commit_manually(using="default"):
             Reporter.objects.create(first_name="Walter", last_name="Cronkite")
예제 #2
0
 def test_manually_managed_mistake(self):
     """
     If you forget, you'll get bad errors.
     """
     with self.assertRaises(transaction.TransactionManagementError):
         with transaction.commit_manually():
             Reporter.objects.create(first_name="Scott", last_name="Browning")
예제 #3
0
 def test_manually_managed(self):
     """
     You can manually manage transactions if you really want to, but you
     have to remember to commit/rollback.
     """
     manually_managed = transaction.commit_manually(self.manually_managed)
     manually_managed()
     self.assertEqual(Reporter.objects.count(), 1)
예제 #4
0
 def test_manually_managed(self):
     """
     You can manually manage transactions if you really want to, but you
     have to remember to commit/rollback.
     """
     with transaction.commit_manually():
         Reporter.objects.create(first_name="Libby", last_name="Holtzman")
         transaction.commit()
     self.assertEqual(Reporter.objects.count(), 1)
예제 #5
0
 def test_manually_managed_mistake(self):
     """
     If you forget, you'll get bad errors.
     """
     manually_managed_mistake = transaction.commit_manually(
         self.manually_managed_mistake
     )
     self.assertRaises(transaction.TransactionManagementError,
         manually_managed_mistake)
예제 #6
0
 def test_manually_managed_with_using(self):
     """
     The commit_manually function also works with a using argument.
     """
     using_manually_managed_mistake = transaction.commit_manually(using='default')(
         self.manually_managed_mistake
     )
     self.assertRaises(transaction.TransactionManagementError,
         using_manually_managed_mistake
     )
예제 #7
0
    def test_syncdb(self):
        with transaction.commit_manually():
            Book.objects.all().delete()

            management.call_command(
                'syncdb',
                verbosity=0,
                load_initial_data=False
            )
            self.assertQuerysetEqual(Book.objects.all(), [])
            transaction.rollback()
예제 #8
0
    def test_flush(self):
        # Test presence of fixture (flush called by TransactionTestCase)
        self.assertQuerysetEqual(
            Book.objects.all(), [
                'Achieving self-awareness of Python programs'
            ],
            lambda a: a.name
        )

        with transaction.commit_manually():
            management.call_command(
                'flush',
                verbosity=0,
                interactive=False,
                commit=False,
                load_initial_data=False
            )
            self.assertQuerysetEqual(Book.objects.all(), [])
            transaction.rollback()
예제 #9
0
 def test_check_constraints(self):
     """
     Constraint checks should raise an IntegrityError when bad data is in the DB.
     """
     with transaction.commit_manually():
         # Create an Article.
         models.Article.objects.create(
             headline="Test article", pub_date=datetime.datetime(2010, 9, 4), reporter=self.r
         )
         # Retrive it from the DB
         a = models.Article.objects.get(headline="Test article")
         a.reporter_id = 30
         try:
             with connection.constraint_checks_disabled():
                 a.save()
                 with self.assertRaises(IntegrityError):
                     connection.check_constraints()
         finally:
             transaction.rollback()
예제 #10
0
 def test_disable_constraint_checks_context_manager(self):
     """
     When constraint checks are disabled (using context manager), should be able to write bad data without IntegrityErrors.
     """
     with transaction.commit_manually():
         # Create an Article.
         models.Article.objects.create(
             headline="Test article", pub_date=datetime.datetime(2010, 9, 4), reporter=self.r
         )
         # Retrive it from the DB
         a = models.Article.objects.get(headline="Test article")
         a.reporter_id = 30
         try:
             with connection.constraint_checks_disabled():
                 a.save()
         except IntegrityError:
             self.fail("IntegrityError should not have occurred.")
         finally:
             transaction.rollback()
예제 #11
0
 def test_ticket_11101(self):
     """Test that fixtures can be rolled back (ticket #11101)."""
     ticket_11101 = transaction.commit_manually(self.ticket_11101)
     ticket_11101()