[FIX] ir_sequence: forgot id argument in _create_sequence().

bzr revid: vmt@openerp.com-20110928103009-17rw1af5ebauu3f5
This commit is contained in:
Vo Minh Thu 2011-09-28 12:30:09 +02:00
parent 5f4ebc7b1c
commit f2c5556b68
4 changed files with 129 additions and 51 deletions

View File

@ -54,7 +54,7 @@ class ir_sequence(openerp.osv.osv.osv):
_order = 'name'
_columns = {
'name': openerp.osv.fields.char('Name', size=64, required=True),
'code': openerp.osv.fields.selection(_code_get, 'Code', size=64, required=True), # TODO should it be unique?
'code': openerp.osv.fields.selection(_code_get, 'Code', size=64, required=True),
'implementation': openerp.osv.fields.selection( # TODO update the view
IMPLEMENTATION_SELECTION, 'Implementation', required=True,
help="Two sequence object implementations are offered: Standard "
@ -79,8 +79,8 @@ class ir_sequence(openerp.osv.osv.osv):
def create(self, cr, uid, values, context=None):
values = self._add_missing_default_values(cr, uid, values, context)
go = super(ir_sequence, self).create_postgres \
if values['implementation'] == 'standard' else self.create
go = super(ir_sequence, self).create \
if values['implementation'] == 'no_gap' else self.create_postgres
return go(cr, uid, values, context)
def create_postgres(self, cr, uid, values, context=None):
@ -92,7 +92,7 @@ class ir_sequence(openerp.osv.osv.osv):
:return: id of the newly created record
"""
id = super(ir_sequence, self).create(cr, uid, values, context)
self._create_sequence(cr,
self._create_sequence(cr, id,
values['number_increment'], values['number_next'])
return id
@ -161,7 +161,7 @@ class ir_sequence(openerp.osv.osv.osv):
if res['implementation'] == 'standard':
cr.execute("""
SELECT nextval('ir_sequence_%03d')
""", (res['id'],))
""" % res['id'])
res['number_next'] = cr.fetchone()
else:
cr.execute("""
@ -207,14 +207,15 @@ class ir_sequence(openerp.osv.osv.osv):
""" % code_or_id, (sequence_code_or_id, tuple(company_ids)))
return cr.dictfetchone()
def _create_sequence(self, cr, number_increment, number_next):
def _create_sequence(self, cr, id, number_increment, number_next):
""" Create a PostreSQL sequence.
There is no access rights check.
"""
assert isinstance(id, (int, long))
cr.execute("""
CREATE SEQUENCE ir_sequence_%03d INCREMENT BY %s START WITH %s
""", (id, number_increment, number_next))
CREATE SEQUENCE ir_sequence_%03d INCREMENT BY %%s START WITH %%s
""" % id, (number_increment, number_next))
def _drop_sequence(self, cr, ids):
""" Drop the PostreSQL sequence if it exists.
@ -238,9 +239,10 @@ class ir_sequence(openerp.osv.osv.osv):
There is no access rights check.
"""
assert isinstance(id, (int, long))
cr.execute("""
ALTER SEQUENCE ir_sequence_%03d INCREMENT BY %s RESTART WITH %s
""", (id, number_increment, number_next))
ALTER SEQUENCE ir_sequence_%03d INCREMENT BY %%s RESTART WITH %%s
""" % id, (number_increment, number_next))
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

47
tests/common.py Normal file
View File

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
import os
import time
import unittest2
import xmlrpclib
import openerp
ADDONS_PATH = os.environ['OPENERP_ADDONS_PATH']
PORT = int(os.environ['OPENERP_PORT'])
DB = os.environ['OPENERP_DATABASE']
HOST = '127.0.0.1'
ADMIN_USER = 'admin'
ADMIN_USER_ID = 1
ADMIN_PASSWORD = 'admin'
common_proxy_60 = None
db_proxy_60 = None
object_proxy_60 = None
def setUpModule():
"""
Start the OpenERP server similary to the openerp-server script and
setup some xmlrpclib proxies.
"""
openerp.tools.config['addons_path'] = ADDONS_PATH
openerp.tools.config['xmlrpc_port'] = PORT
openerp.service.start_services()
global common_proxy_60
global db_proxy_60
global object_proxy_60
# Use the old (pre 6.1) API.
url = 'http://%s:%d/xmlrpc/' % (HOST, PORT)
common_proxy_60 = xmlrpclib.ServerProxy(url + 'common')
db_proxy_60 = xmlrpclib.ServerProxy(url + 'db')
object_proxy_60 = xmlrpclib.ServerProxy(url + 'object')
# Ugly way to ensure the server is listening.
time.sleep(2)
def tearDownModule():
""" Shutdown the OpenERP server similarly to a single ctrl-c. """
openerp.service.stop_services()

57
tests/test_ir_sequence.py Normal file
View File

@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Run with one of these commands:
# > OPENERP_ADDONS_PATH='../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy PYTHONPATH=. python tests/test_ir_sequence.py
# > OPENERP_ADDONS_PATH='../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy nosetests tests/test_ir_sequence.py
# > OPENERP_ADDONS_PATH='../../../addons/trunk' OPENERP_PORT=8069 \
# OPENERP_DATABASE=yy PYTHONPATH=../:. unit2 test_ir_sequence
import os
import time
import unittest2
import xmlrpclib
import openerp
import common
DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID
setUpModule = common.setUpModule
tearDownModule = common.tearDownModule
def registry(model):
return openerp.modules.registry.RegistryManager.get(DB)[model]
def cursor():
return openerp.modules.registry.RegistryManager.get(DB).db.cursor()
class test_ir_sequence(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()
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()
if __name__ == '__main__':
unittest2.main()

View File

@ -12,43 +12,15 @@ import unittest2
import xmlrpclib
import openerp
import common
ADDONS_PATH = os.environ['OPENERP_ADDONS_PATH']
PORT = int(os.environ['OPENERP_PORT'])
DB = os.environ['OPENERP_DATABASE']
DB = common.DB
ADMIN_USER = common.ADMIN_USER
ADMIN_USER_ID = common.ADMIN_USER_ID
ADMIN_PASSWORD = common.ADMIN_PASSWORD
HOST = '127.0.0.1'
ADMIN_USER = 'admin'
ADMIN_USER_ID = 1
ADMIN_PASSWORD = 'admin'
common_proxy_60 = None
db_proxy_60 = None
object_proxy_60 = None
def setUpModule():
"""
Start the OpenERP server similary to the openerp-server script and
setup some xmlrpclib proxies.
"""
openerp.tools.config['addons_path'] = ADDONS_PATH
openerp.tools.config['xmlrpc_port'] = PORT
openerp.service.start_services()
global common_proxy_60
global db_proxy_60
global object_proxy_60
# Use the old (pre 6.1) API.
url = 'http://%s:%d/xmlrpc/' % (HOST, PORT)
common_proxy_60 = xmlrpclib.ServerProxy(url + 'common')
db_proxy_60 = xmlrpclib.ServerProxy(url + 'db')
object_proxy_60 = xmlrpclib.ServerProxy(url + 'object')
def tearDownModule():
""" Shutdown the OpenERP server similarly to a single ctrl-c. """
openerp.service.stop_services()
setUpModule = common.setUpModule
tearDownModule = common.tearDownModule
class test_xmlrpc(unittest2.TestCase):
@ -57,26 +29,26 @@ class test_xmlrpc(unittest2.TestCase):
Simulate a OpenERP client requesting the creation of a database and
polling the server until the creation is complete.
"""
progress_id = db_proxy_60.create(ADMIN_PASSWORD, DB, True, False,
ADMIN_PASSWORD)
progress_id = common.db_proxy_60.create(ADMIN_PASSWORD, DB, True,
False, ADMIN_PASSWORD)
while True:
time.sleep(1)
progress, users = db_proxy_60.get_progress(ADMIN_PASSWORD,
progress, users = common.db_proxy_60.get_progress(ADMIN_PASSWORD,
progress_id)
if progress == 1.0:
break
def test_xmlrpc_login(self):
""" Try to login on the common service. """
uid = common_proxy_60.login(DB, ADMIN_USER, ADMIN_PASSWORD)
uid = common.common_proxy_60.login(DB, ADMIN_USER, ADMIN_PASSWORD)
assert uid == ADMIN_USER_ID
def test_xmlrpc_ir_model_search(self):
""" Try a search on the object service. """
ids = object_proxy_60.execute(DB, ADMIN_USER_ID, ADMIN_PASSWORD,
ids = common.object_proxy_60.execute(DB, ADMIN_USER_ID, ADMIN_PASSWORD,
'ir.model', 'search', [])
assert ids
ids = object_proxy_60.execute(DB, ADMIN_USER_ID, ADMIN_PASSWORD,
ids = common.object_proxy_60.execute(DB, ADMIN_USER_ID, ADMIN_PASSWORD,
'ir.model', 'search', [], {})
assert ids