Fixed #18347 -- Removed autofield raw SQL inserts from tests

This commit is contained in:
Anssi Kääriäinen 2012-06-08 15:57:42 +03:00
parent f51e409a5f
commit 71e14cf3aa
1 changed files with 10 additions and 15 deletions

View File

@ -24,17 +24,15 @@ class TestTransactionClosing(TransactionTestCase):
def raw_sql(): def raw_sql():
"Write a record using raw sql under a commit_on_success decorator" "Write a record using raw sql under a commit_on_success decorator"
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("INSERT into transactions_regress_mod (id,fld) values (17,18)") cursor.execute("INSERT into transactions_regress_mod (fld) values (18)")
raw_sql() raw_sql()
# Rollback so that if the decorator didn't commit, the record is unwritten # Rollback so that if the decorator didn't commit, the record is unwritten
transaction.rollback() transaction.rollback()
try: self.assertEqual(Mod.objects.count(), 1)
# Check that the record is in the DB # Check that the record is in the DB
obj = Mod.objects.get(pk=17) obj = Mod.objects.all()[0]
self.assertEqual(obj.fld, 18) self.assertEqual(obj.fld, 18)
except Mod.DoesNotExist:
self.fail("transaction with raw sql not committed")
def test_commit_manually_enforced(self): def test_commit_manually_enforced(self):
""" """
@ -115,19 +113,16 @@ class TestTransactionClosing(TransactionTestCase):
be committed. be committed.
""" """
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute("INSERT into transactions_regress_mod (id,fld) values (1,2)") cursor.execute("INSERT into transactions_regress_mod (fld) values (2)")
transaction.rollback() transaction.rollback()
cursor.execute("INSERT into transactions_regress_mod (id,fld) values (1,2)") cursor.execute("INSERT into transactions_regress_mod (fld) values (2)")
reuse_cursor_ref() reuse_cursor_ref()
# Rollback so that if the decorator didn't commit, the record is unwritten # Rollback so that if the decorator didn't commit, the record is unwritten
transaction.rollback() transaction.rollback()
try: self.assertEqual(Mod.objects.count(), 1)
# Check that the record is in the DB obj = Mod.objects.all()[0]
obj = Mod.objects.get(pk=1) self.assertEqual(obj.fld, 2)
self.assertEqual(obj.fld, 2)
except Mod.DoesNotExist:
self.fail("After ending a transaction, cursor use no longer sets dirty")
def test_failing_query_transaction_closed(self): def test_failing_query_transaction_closed(self):
""" """