NotUniqueError gracefully replacing ambiguous OperationError when appropriate

This commit is contained in:
Ross Lawley
2012-08-24 10:38:00 +01:00
parent eedf908770
commit 1c5e6a3425
4 changed files with 23 additions and 9 deletions

View File

@@ -1013,6 +1013,9 @@ class DocumentTest(unittest.TestCase):
# Two posts with the same slug is not allowed
post2 = BlogPost(title='test2', slug='test')
self.assertRaises(NotUniqueError, post2.save)
# Ensure backwards compatibilty for errors
self.assertRaises(OperationError, post2.save)
def test_unique_with(self):
@@ -1063,7 +1066,7 @@ class DocumentTest(unittest.TestCase):
# Now there will be two docs with the same sub.slug
post3 = BlogPost(title='test3', sub=SubDocument(year=2010, slug='test'))
self.assertRaises(OperationError, post3.save)
self.assertRaises(NotUniqueError, post3.save)
BlogPost.drop_collection()
@@ -1090,11 +1093,11 @@ class DocumentTest(unittest.TestCase):
# Now there will be two docs with the same sub.slug
post3 = BlogPost(title='test3', sub=SubDocument(year=2010, slug='test'))
self.assertRaises(OperationError, post3.save)
self.assertRaises(NotUniqueError, post3.save)
# Now there will be two docs with the same title and year
post3 = BlogPost(title='test1', sub=SubDocument(year=2009, slug='test-1'))
self.assertRaises(OperationError, post3.save)
self.assertRaises(NotUniqueError, post3.save)
BlogPost.drop_collection()
@@ -1117,7 +1120,7 @@ class DocumentTest(unittest.TestCase):
try:
cust_dupe.save()
raise AssertionError, "We saved a dupe!"
except OperationError:
except NotUniqueError:
pass
Customer.drop_collection()

View File

@@ -578,7 +578,7 @@ class QuerySetTest(unittest.TestCase):
def throw_operation_error_not_unique():
Blog.objects.insert([blog2, blog3], safe=True)
self.assertRaises(OperationError, throw_operation_error_not_unique)
self.assertRaises(NotUniqueError, throw_operation_error_not_unique)
self.assertEqual(Blog.objects.count(), 2)
Blog.objects.insert([blog2, blog3], write_options={'continue_on_error': True})