[MERGE] test_cursor: adapt code to small api changes in registry for handling http tests

bzr revid: rco@openerp.com-20140409150002-le29vuu4x41j61q6
This commit is contained in:
Raphael Collet
2014-04-09 17:00:02 +02:00
6 changed files with 61 additions and 48 deletions
+2 -2
View File
@@ -2005,7 +2005,7 @@ class nodefd_content(StringIO, node_descriptor):
par = self._get_parent()
uid = par.context.uid
cr = openerp.registry(par.context.dbname).db.cursor()
cr = openerp.registry(par.context.dbname).cursor()
try:
if self.mode in ('w', 'w+', 'r+'):
data = self.getvalue()
@@ -2058,7 +2058,7 @@ class nodefd_static(StringIO, node_descriptor):
par = self._get_parent()
# uid = par.context.uid
cr = openerp.registry(par.context.dbname).db.cursor()
cr = openerp.registry(par.context.dbname).cursor()
try:
if self.mode in ('w', 'w+', 'r+'):
data = self.getvalue()
+4 -8
View File
@@ -34,18 +34,14 @@ def _edi_dispatch(db_name, method_name, *method_args):
try:
registry = openerp.modules.registry.RegistryManager.get(db_name)
assert registry, 'Unknown database %s' % db_name
edi = registry['edi.edi']
cr = registry.db.cursor()
res = None
res = getattr(edi, method_name)(cr, *method_args)
cr.commit()
with registry.cursor() as cr:
edi = registry['edi.edi']
return getattr(edi, method_name)(cr, *method_args)
except Exception, e:
_logger.exception('Failed to execute EDI method %s with args %r.',
method_name, method_args)
raise
finally:
cr.close()
return res
def exp_import_edi_document(db_name, uid, passwd, edi_document, context=None):
return _edi_dispatch(db_name, 'import_edi', uid, edi_document, None)
+2 -2
View File
@@ -59,7 +59,7 @@ class procurement_order(osv.osv):
context = {}
try:
if use_new_cursor:
cr = openerp.registry(use_new_cursor).db.cursor()
cr = openerp.registry(use_new_cursor).cursor()
procurement_obj = self.pool.get('procurement.order')
if not skip_exception:
@@ -199,7 +199,7 @@ class procurement_order(osv.osv):
if context is None:
context = {}
if use_new_cursor:
cr = openerp.registry(use_new_cursor).db.cursor()
cr = openerp.registry(use_new_cursor).cursor()
orderpoint_obj = self.pool.get('stock.warehouse.orderpoint')
procurement_obj = self.pool.get('procurement.order')
@@ -49,7 +49,7 @@ class procurement_compute(osv.osv_memory):
"""
proc_obj = self.pool.get('procurement.order')
#As this function is in a new thread, I need to open a new cursor, because the old one may be closed
new_cr = self.pool.db.cursor()
new_cr = self.pool.cursor()
for proc in self.browse(new_cr, uid, ids, context=context):
proc_obj._procure_orderpoint_confirm(new_cr, uid, automatic=proc.automatic, use_new_cursor=new_cr.dbname, context=context)
#close the new cursor
+1 -1
View File
@@ -45,7 +45,7 @@ class procurement_compute_all(osv.osv_memory):
"""
proc_obj = self.pool.get('procurement.order')
#As this function is in a new thread, i need to open a new cursor, because the old one may be closed
new_cr = self.pool.db.cursor()
new_cr = self.pool.cursor()
for proc in self.browse(new_cr, uid, ids, context=context):
proc_obj.run_scheduler(new_cr, uid, automatic=proc.automatic, use_new_cursor=new_cr.dbname,\
context=context)
+51 -34
View File
@@ -6,6 +6,7 @@ import werkzeug.urls
import lxml.html
import openerp
from openerp import tools
import cases
@@ -43,15 +44,23 @@ class CrawlSuite(unittest2.TestSuite):
def __init__(self, user=None, password=None):
super(CrawlSuite, self).__init__()
self.opener = urllib2.OpenerDirector()
self.opener.add_handler(urllib2.UnknownHandler())
self.opener.add_handler(urllib2.HTTPHandler())
self.opener.add_handler(urllib2.HTTPSHandler())
self.opener.add_handler(urllib2.HTTPCookieProcessor())
self.opener.add_handler(RedirectHandler())
registry = openerp.registry(tools.config['db_name'])
try:
# switch registry to test mode, so that requests can be made
registry.enter_test_mode()
self._authenticate(user, password)
self.user = user
self.opener = urllib2.OpenerDirector()
self.opener.add_handler(urllib2.UnknownHandler())
self.opener.add_handler(urllib2.HTTPHandler())
self.opener.add_handler(urllib2.HTTPSHandler())
self.opener.add_handler(urllib2.HTTPCookieProcessor())
self.opener.add_handler(RedirectHandler())
self._authenticate(user, password)
self.user = user
finally:
registry.leave_test_mode()
def _request(self, path):
return self.opener.open(urlparse.urlunsplit([
@@ -79,37 +88,45 @@ class CrawlSuite(unittest2.TestSuite):
assert auth.getcode() < 400, "Auth failure %d" % auth.getcode()
def _wrapped_run(self, result, debug=False):
paths = [URL('/'), URL('/sitemap')]
seen = set(paths)
registry = openerp.registry(tools.config['db_name'])
try:
# switch registry to test mode, so that requests can be made
registry.enter_test_mode()
while paths:
url = paths.pop(0)
r = self._request(url.url)
url.to_case(self.user, r).run(result)
paths = [URL('/'), URL('/sitemap')]
seen = set(paths)
if r.info().gettype() != 'text/html':
continue
while paths:
url = paths.pop(0)
r = self._request(url.url)
url.to_case(self.user, r).run(result)
doc = lxml.html.fromstring(r.read())
for link in doc.xpath('//a[@href]'):
href = link.get('href')
# avoid repeats, even for links we won't crawl no need to
# bother splitting them if we've already ignored them
# previously
if href in seen: continue
seen.add(href)
parts = urlparse.urlsplit(href)
if parts.netloc or \
not parts.path.startswith('/') or \
parts.path == '/web' or\
parts.path.startswith('/web/') or \
(parts.scheme and parts.scheme not in ('http', 'https')):
if r.info().gettype() != 'text/html':
continue
paths.append(URL(href, url.url))
doc = lxml.html.fromstring(r.read())
for link in doc.xpath('//a[@href]'):
href = link.get('href')
# avoid repeats, even for links we won't crawl no need to
# bother splitting them if we've already ignored them
# previously
if href in seen: continue
seen.add(href)
parts = urlparse.urlsplit(href)
if parts.netloc or \
not parts.path.startswith('/') or \
parts.path == '/web' or\
parts.path.startswith('/web/') or \
(parts.scheme and parts.scheme not in ('http', 'https')):
continue
paths.append(URL(href, url.url))
finally:
registry.leave_test_mode()
class URL(object):
def __init__(self, url, source=None):