[FIX] Test for ir_sequence:
authorRichard Mathot (OpenERP) <rim@openerp.com>
Thu, 6 Mar 2014 11:03:56 +0000 (12:03 +0100)
committerRichard Mathot (OpenERP) <rim@openerp.com>
Thu, 6 Mar 2014 11:03:56 +0000 (12:03 +0100)
This test was depending on the error string returned by postgresql.
As these strings are localized, the test was failing on systems
where posgresql locale was not set to 'en_US'.

In this new version, we now check the error code returned by postgresql
(which is, obviously, platform independent)

bzr revid: rim@openerp.com-20140306110356-72mgz3korkq3rkde

openerp/tests/test_ir_sequence.py

index cbb1a34..280eb9f 100644 (file)
@@ -8,6 +8,7 @@
 #      OPENERP_DATABASE=yy PYTHONPATH=../:. unit2 test_ir_sequence
 # This assume an existing database.
 import psycopg2
+import psycopg2.errorcodes
 import unittest2
 
 import openerp
@@ -111,11 +112,11 @@ class test_ir_sequence_no_gap(unittest2.TestCase):
         cr0 = cursor()
         cr1 = cursor()
         cr1._default_log_exceptions = False # Prevent logging a traceback
-        msg_re = '^could not obtain lock on row in relation "ir_sequence"$'
-        with self.assertRaisesRegexp(psycopg2.OperationalError, msg_re):
+        with self.assertRaises(psycopg2.OperationalError) as e:
             n0 = registry('ir.sequence').next_by_code(cr0, ADMIN_USER_ID, 'test_sequence_type_2', {})
             assert n0
             n1 = registry('ir.sequence').next_by_code(cr1, ADMIN_USER_ID, 'test_sequence_type_2', {})
+        assert e.exception.pgcode == psycopg2.errorcodes.LOCK_NOT_AVAILABLE
         cr0.close()
         cr1.close()