diff options
| author | Vo Minh Thu <vmt@openerp.com> | 2011-09-28 16:15:20 +0200 |
|---|---|---|
| committer | Vo Minh Thu <vmt@openerp.com> | 2011-09-28 16:15:20 +0200 |
| commit | 538cc0e92f9fbc993bec5a224de4c3f38b9a13e6 (patch) | |
| tree | f7ba0e5e4f05e40200072637cba2733d17c360b5 /tests/test_ir_sequence.py | |
| parent | 6929d9f3c85d7623c86487e030c8464bb0d6c530 (diff) | |
[FIX] ir_sequence: typo in read().
bzr revid: vmt@openerp.com-20110928141520-9yx9sogoetizb9nn
Diffstat (limited to 'tests/test_ir_sequence.py')
| -rw-r--r-- | tests/test_ir_sequence.py | 143 |
1 files changed, 85 insertions, 58 deletions
diff --git a/tests/test_ir_sequence.py b/tests/test_ir_sequence.py index 0fc7aec5b50..13c40dd6eb3 100644 --- a/tests/test_ir_sequence.py +++ b/tests/test_ir_sequence.py @@ -33,51 +33,43 @@ class test_ir_sequence_standard(unittest2.TestCase): def test_ir_sequence_create(self): """ Try to create a sequence object. """ cr = cursor() - try: - d = dict(code='test_sequence_type', name='Test sequence type') - c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {}) - assert c - d = dict(code='test_sequence_type', name='Test sequence') - c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {}) - assert c - cr.commit() - finally: - cr.close() + d = dict(code='test_sequence_type', name='Test sequence type') + c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {}) + assert c + d = dict(code='test_sequence_type', name='Test sequence') + c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {}) + assert c + cr.commit() + cr.close() def test_ir_sequence_search(self): """ Try a search. """ cr = cursor() - try: - ids = registry('ir.sequence').search(cr, ADMIN_USER_ID, [], {}) - assert ids - cr.commit() - finally: - cr.close() + ids = registry('ir.sequence').search(cr, ADMIN_USER_ID, [], {}) + assert ids + cr.commit() + 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() + n = registry('ir.sequence').get(cr, ADMIN_USER_ID, 'test_sequence_type', {}) + assert n + cr.commit() + 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() + 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() + cr0.close() + cr1.close() class test_ir_sequence_no_gap(unittest2.TestCase): """ Copy of the previous tests for a 'No gap' sequence. """ @@ -85,27 +77,23 @@ class test_ir_sequence_no_gap(unittest2.TestCase): 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() + 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() + 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() + n = registry('ir.sequence').get(cr, ADMIN_USER_ID, 'test_sequence_type_2', {}) + assert n + cr.commit() + cr.close() def test_ir_sequence_draw_twice_no_gap(self): """ Try to draw a number from two transactions. @@ -113,15 +101,54 @@ class test_ir_sequence_no_gap(unittest2.TestCase): """ 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() + 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', {}) + cr0.close() + cr1.close() + +class test_ir_sequence_change_implementation(unittest2.TestCase): + """ Create sequence objects and change their ``implementation`` field. """ + + def test_ir_sequence_1_create(self): + """ Try to create a sequence object. """ + cr = cursor() + d = dict(code='test_sequence_type_3', name='Test sequence type') + c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {}) + assert c + d = dict(code='test_sequence_type_3', name='Test sequence') + c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {}) + assert c + d = dict(code='test_sequence_type_4', name='Test sequence type') + c = registry('ir.sequence.type').create(cr, ADMIN_USER_ID, d, {}) + assert c + d = dict(code='test_sequence_type_4', name='Test sequence', + implementation='no_gap') + c = registry('ir.sequence').create(cr, ADMIN_USER_ID, d, {}) + assert c + cr.commit() + cr.close() + + def test_ir_sequence_2_write(self): + cr = cursor() + ids = registry('ir.sequence').search(cr, ADMIN_USER_ID, + [('code', 'in', ['test_sequence_type_3', 'test_sequence_type_4'])], {}) + registry('ir.sequence').write(cr, ADMIN_USER_ID, ids, + {'implementation': 'standard'}, {}) + registry('ir.sequence').write(cr, ADMIN_USER_ID, ids, + {'implementation': 'no_gap'}, {}) + cr.commit() + cr.close() + + def test_ir_sequence_3_unlink(self): + cr = cursor() + ids = registry('ir.sequence').search(cr, ADMIN_USER_ID, + [('code', 'in', ['test_sequence_type_3', 'test_sequence_type_4'])], {}) + registry('ir.sequence').unlink(cr, ADMIN_USER_ID, ids, {}) + cr.commit() + cr.close() if __name__ == '__main__': |
