diff options
| author | Vo Minh Thu <vmt@openerp.com> | 2011-09-28 13:42:29 +0200 |
|---|---|---|
| committer | Vo Minh Thu <vmt@openerp.com> | 2011-09-28 13:42:29 +0200 |
| commit | eeaa2a7f8073153e5bb838ff5ace51215d18d68a (patch) | |
| tree | 7c071cbe20856e0afdf1f79c1a8be3c7cb07d1b0 /tests/test_ir_sequence.py | |
| parent | f2c5556b68f6879766dadf6522e35f4afc16696e (diff) | |
[FIX] ir_sequence: do the FOR UPDATE NO WAIT only in the No-gap sequence.
bzr revid: vmt@openerp.com-20110928114229-1g6r5et5frj26wam
Diffstat (limited to 'tests/test_ir_sequence.py')
| -rw-r--r-- | tests/test_ir_sequence.py | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/test_ir_sequence.py b/tests/test_ir_sequence.py index ef7e6784daa..0fc7aec5b50 100644 --- a/tests/test_ir_sequence.py +++ b/tests/test_ir_sequence.py @@ -7,6 +7,7 @@ # > OPENERP_ADDONS_PATH='../../../addons/trunk' OPENERP_PORT=8069 \ # OPENERP_DATABASE=yy PYTHONPATH=../:. unit2 test_ir_sequence import os +import psycopg2 import time import unittest2 import xmlrpclib @@ -26,7 +27,8 @@ def registry(model): def cursor(): return openerp.modules.registry.RegistryManager.get(DB).db.cursor() -class test_ir_sequence(unittest2.TestCase): +class test_ir_sequence_standard(unittest2.TestCase): + """ A few tests for a 'Standard' (i.e. PostgreSQL) sequence. """ def test_ir_sequence_create(self): """ Try to create a sequence object. """ @@ -52,6 +54,76 @@ class test_ir_sequence(unittest2.TestCase): finally: cr.close() + def test_ir_sequence_draw(self): + """ Try to draw a number. """ + cr = cursor() + try: + n = registry('ir.sequence').get(cr, ADMIN_USER_ID, 'test_sequence_type', {}) + assert n + cr.commit() + finally: + cr.close() + + def test_ir_sequence_draw_twice(self): + """ Try to draw a number from two transactions. """ + cr0 = cursor() + cr1 = cursor() + try: + n0 = registry('ir.sequence').get(cr0, ADMIN_USER_ID, 'test_sequence_type', {}) + assert n0 + n1 = registry('ir.sequence').get(cr1, ADMIN_USER_ID, 'test_sequence_type', {}) + assert n1 + cr0.commit() + cr1.commit() + finally: + cr0.close() + cr1.close() + +class test_ir_sequence_no_gap(unittest2.TestCase): + """ Copy of the previous tests for a 'No gap' sequence. """ + + def test_ir_sequence_create_no_gap(self): + """ Try to create a sequence object. """ + cr = cursor() + try: + d = dict(code='test_sequence_type_2', name='Test sequence type') + c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {}) + assert c + d = dict(code='test_sequence_type_2', name='Test sequence', + implementation='no_gap') + c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {}) + assert c + cr.commit() + finally: + cr.close() + + def test_ir_sequence_draw_no_gap(self): + """ Try to draw a number. """ + cr = cursor() + try: + n = registry('ir.sequence').get(cr, ADMIN_USER_ID, 'test_sequence_type_2', {}) + assert n + cr.commit() + finally: + cr.close() + + def test_ir_sequence_draw_twice_no_gap(self): + """ Try to draw a number from two transactions. + This is expected to not work. + """ + cr0 = cursor() + cr1 = cursor() + try: + msg_re = '^could not obtain lock on row in relation "ir_sequence"$' + with self.assertRaisesRegexp(psycopg2.OperationalError, msg_re): + n0 = registry('ir.sequence').get(cr0, ADMIN_USER_ID, 'test_sequence_type_2', {}) + assert n0 + n1 = registry('ir.sequence').get(cr1, ADMIN_USER_ID, 'test_sequence_type_2', {}) + finally: + cr0.close() + cr1.close() + + if __name__ == '__main__': unittest2.main() |
