Author: mtredinnick
Date: 2008-08-20 13:50:06 -0500 (Wed, 20 Aug 2008)
New Revision: 8450
Modified:
django/trunk/tests/modeltests/force_insert_update/models.py
django/trunk/tests/modeltests/get_or_create/models.py
django/trunk/tests/modeltests/one_to_one/models.py
Log:
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.
Modified: django/trunk/tests/modeltests/force_insert_update/models.py
===================================================================
--- django/trunk/tests/modeltests/force_insert_update/models.py 2008-08-20
15:56:07 UTC (rev 8449)
+++ django/trunk/tests/modeltests/force_insert_update/models.py 2008-08-20
18:50:06 UTC (rev 8450)
@@ -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 @@
# 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
Modified: django/trunk/tests/modeltests/get_or_create/models.py
===================================================================
--- django/trunk/tests/modeltests/get_or_create/models.py 2008-08-20
15:56:07 UTC (rev 8449)
+++ django/trunk/tests/modeltests/get_or_create/models.py 2008-08-20
18:50:06 UTC (rev 8450)
@@ -6,7 +6,7 @@
parameters.
"""
-from django.db import models
+from django.db import models, IntegrityError
class Person(models.Model):
first_name = models.CharField(max_length=100)
@@ -53,8 +53,12 @@
# If you don't specify a value or default value for all required fields, you
# will get an error.
->>> p, created = Person.objects.get_or_create(first_name='Tom',
last_name='Smith')
-Traceback (most recent call last):
-...
-IntegrityError:...
+>>> try:
+... p, created = Person.objects.get_or_create(first_name='Tom',
last_name='Smith')
+... except Exception, e:
+... if isinstance(e, IntegrityError):
+... print "Pass"
+... else:
+... print "Fail with %s" % type(e)
+Pass
"""}
Modified: django/trunk/tests/modeltests/one_to_one/models.py
===================================================================
--- django/trunk/tests/modeltests/one_to_one/models.py 2008-08-20 15:56:07 UTC
(rev 8449)
+++ django/trunk/tests/modeltests/one_to_one/models.py 2008-08-20 18:50:06 UTC
(rev 8450)
@@ -6,7 +6,7 @@
In this example, a ``Place`` optionally can be a ``Restaurant``.
"""
-from django.db import models, transaction
+from django.db import models, transaction, IntegrityError
class Place(models.Model):
name = models.CharField(max_length=50)
@@ -179,10 +179,14 @@
# This will fail because each one-to-one field must be unique (and link2=o1 was
# used for x1, above).
>>> sid = transaction.savepoint()
->>> MultiModel(link1=p2, link2=o1, name="x1").save()
-Traceback (most recent call last):
- ...
-IntegrityError: ...
+>>> try:
+... MultiModel(link1=p2, link2=o1, name="x1").save()
+... except Exception, e:
+... if isinstance(e, IntegrityError):
+... print "Pass"
+... else:
+... print "Fail with %s" % type(e)
+Pass
>>> transaction.savepoint_rollback(sid)
"""}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---