From e94d29350446df6a87e0fd2b867a47e06295ae98 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 20 Aug 2008 18:50:06 +0000 Subject: There are some variations in the printed names of exceptions between Oracle and other database backends, but the exception classes should still be the same. This commit changes the way the tests check for specific database errors to be more portable between implementations. It's possible these tests will still fail if, e.g., Oracle doesn't raise IntegrityError (but raises DatabaseError) when we except it to, but we can cross that bridge if and when it appears. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8450 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/force_insert_update/models.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests/modeltests/force_insert_update/models.py') diff --git a/tests/modeltests/force_insert_update/models.py b/tests/modeltests/force_insert_update/models.py index c9b9fe0c76..2489740e98 100644 --- a/tests/modeltests/force_insert_update/models.py +++ b/tests/modeltests/force_insert_update/models.py @@ -2,7 +2,7 @@ Tests for forcing insert and update queries (instead of Django's normal automatic behaviour). """ -from django.db import models, transaction +from django.db import models, transaction, IntegrityError class Counter(models.Model): name = models.CharField(max_length = 10) @@ -42,10 +42,14 @@ ValueError: Cannot force an update in save() with no primary key. # Won't work because we can't insert a pk of the same value. >>> sid = transaction.savepoint() >>> c.value = 5 ->>> c.save(force_insert=True) -Traceback (most recent call last): -... -IntegrityError: ... +>>> try: +... c.save(force_insert=True) +... except Exception, e: +... if isinstance(e, IntegrityError): +... print "Pass" +... else: +... print "Fail with %s" % type(e) +Pass >>> transaction.savepoint_rollback(sid) # Trying to update should still fail, even with manual primary keys, if the -- cgit v1.3