summaryrefslogtreecommitdiff
path: root/tests/force_insert_update
diff options
context:
space:
mode:
Diffstat (limited to 'tests/force_insert_update')
-rw-r--r--tests/force_insert_update/tests.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/force_insert_update/tests.py b/tests/force_insert_update/tests.py
index 706a099872..6d87151d83 100644
--- a/tests/force_insert_update/tests.py
+++ b/tests/force_insert_update/tests.py
@@ -21,24 +21,29 @@ class ForceTests(TestCase):
# Won't work because force_update and force_insert are mutually
# exclusive
c.value = 4
- self.assertRaises(ValueError, c.save, force_insert=True, force_update=True)
+ with self.assertRaises(ValueError):
+ c.save(force_insert=True, force_update=True)
# Try to update something that doesn't have a primary key in the first
# place.
c1 = Counter(name="two", value=2)
- self.assertRaises(ValueError, c1.save, force_update=True)
+ with self.assertRaises(ValueError):
+ with transaction.atomic():
+ c1.save(force_update=True)
c1.save(force_insert=True)
# Won't work because we can't insert a pk of the same value.
- sid = transaction.savepoint()
c.value = 5
- self.assertRaises(IntegrityError, c.save, force_insert=True)
- transaction.savepoint_rollback(sid)
+ with self.assertRaises(IntegrityError):
+ with transaction.atomic():
+ c.save(force_insert=True)
# Trying to update should still fail, even with manual primary keys, if
# the data isn't in the database already.
obj = WithCustomPK(name=1, value=1)
- self.assertRaises(DatabaseError, obj.save, force_update=True)
+ with self.assertRaises(DatabaseError):
+ with transaction.atomic():
+ obj.save(force_update=True)
class InheritanceTests(TestCase):