コード例 #1
0
ファイル: tests.py プロジェクト: timothyclemans/djangocg
    def test_autocommit_context_manager_with_using(self):
        """
        The autocommit context manager also works with a using argument.
        """
        with self.assertRaises(Exception):
            with transaction.autocommit(using="default"):
                self.create_reporter_and_fail()

        self.assertEqual(Reporter.objects.count(), 1)
コード例 #2
0
ファイル: tests.py プロジェクト: timothyclemans/djangocg
    def test_autocommit_context_manager(self):
        """
        The autocommit context manager works exactly the same as the default
        behavior.
        """
        with self.assertRaises(Exception):
            with transaction.autocommit():
                self.create_reporter_and_fail()

        self.assertEqual(Reporter.objects.count(), 1)
コード例 #3
0
ファイル: tests.py プロジェクト: timothyclemans/djangocg
    def test_commit_on_success_exit(self):
        with transaction.autocommit():
            with transaction.commit_on_success():
                Reporter.objects.create(first_name="Bobby", last_name="Tables")

            # Much more formal
            r = Reporter.objects.get()
            r.first_name = "Robert"
            r.save()

        r = Reporter.objects.get()
        self.assertEqual(r.first_name, "Robert")
コード例 #4
0
ファイル: tests.py プロジェクト: timothyclemans/djangocg
 def test_autocommit_decorator_with_using(self):
     """
     The autocommit decorator also works with a using argument.
     """
     autocomitted_create_then_fail = transaction.autocommit(using='default')(
         self.create_a_reporter_then_fail
     )
     self.assertRaises(Exception,
         autocomitted_create_then_fail,
         "Alice", "Smith"
     )
     # Again, the object created before the exception still exists
     self.assertEqual(Reporter.objects.count(), 1)
コード例 #5
0
ファイル: tests.py プロジェクト: timothyclemans/djangocg
 def test_autocommit_decorator(self):
     """
     The autocommit decorator works exactly the same as the default behavior.
     """
     autocomitted_create_then_fail = transaction.autocommit(
         self.create_a_reporter_then_fail
     )
     self.assertRaises(Exception,
         autocomitted_create_then_fail,
         "Alice", "Smith"
     )
     # Again, the object created before the exception still exists
     self.assertEqual(Reporter.objects.count(), 1)