summaryrefslogtreecommitdiff
path: root/odoo/tools/test_reports.py
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/tools/test_reports.py')
-rw-r--r--odoo/tools/test_reports.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/odoo/tools/test_reports.py b/odoo/tools/test_reports.py
index cad44431c1d..6a6401eb896 100644
--- a/odoo/tools/test_reports.py
+++ b/odoo/tools/test_reports.py
@@ -7,15 +7,14 @@
through the code of yaml tests.
"""
-import odoo
-import odoo.tools as tools
import logging
-
-from odoo.tools import pycompat
-from odoo.tools.safe_eval import safe_eval
-from subprocess import Popen, PIPE
import os
import tempfile
+from subprocess import Popen, PIPE
+
+from .. import api
+from . import pycompat, ustr, config
+from .safe_eval import safe_eval
_logger = logging.getLogger(__name__)
_test_logger = logging.getLogger('odoo.tests')
@@ -30,7 +29,7 @@ def try_report(cr, uid, rname, ids, data=None, context=None, our_module=None, re
context = {}
_test_logger.info(" - Trying %s.create(%r)", rname, ids)
- env = odoo.api.Environment(cr, uid, context)
+ env = api.Environment(cr, uid, context)
report_id = env['ir.actions.report'].search([('report_name', '=', rname)], limit=1)
if not report_id:
@@ -41,12 +40,12 @@ def try_report(cr, uid, rname, ids, data=None, context=None, our_module=None, re
if not res_data:
raise ValueError("Report %s produced an empty result!" % rname)
- if tools.config['test_report_directory']:
- open(os.path.join(tools.config['test_report_directory'], rname+ '.'+res_format), 'wb+').write(res_data)
+ if config['test_report_directory']:
+ open(os.path.join(config['test_report_directory'], rname+ '.'+res_format), 'wb+').write(res_data)
_logger.debug("Have a %s report for %s, will examine it", res_format, rname)
if res_format == 'pdf':
- if res_data[:5] != '%PDF-':
+ if res_data[:5] != b'%PDF-':
raise ValueError("Report %s produced a non-pdf header, %r" % (rname, res_data[:10]))
res_text = False
try:
@@ -56,7 +55,7 @@ def try_report(cr, uid, rname, ids, data=None, context=None, our_module=None, re
proc = Popen(['pdftotext', '-enc', 'UTF-8', '-nopgbrk', rfname, '-'], shell=False, stdout=PIPE)
stdout, stderr = proc.communicate()
- res_text = tools.ustr(stdout)
+ res_text = ustr(stdout)
os.unlink(rfname)
except Exception:
_logger.debug("Unable to parse PDF report: install pdftotext to perform automated tests.")
@@ -92,14 +91,14 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
Eg. 'OK' or 'fa-print'
:param our_module: the name of the calling module (string), like 'account'
"""
- if not our_module and isinstance(action_id, basestring):
+ if not our_module and isinstance(action_id, pycompat.string_types):
if '.' in action_id:
our_module = action_id.split('.', 1)[0]
context = dict(context or {})
# TODO context fill-up
- env = odoo.api.Environment(cr, uid, context)
+ env = api.Environment(cr, uid, context)
def log_test(msg, *args):
_test_logger.info(" - " + msg, *args)
@@ -113,7 +112,7 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
if not wiz_buttons:
wiz_buttons = []
- if isinstance(action_id, basestring):
+ if isinstance(action_id, pycompat.string_types):
if '.' in action_id:
_, act_xmlid = action_id.split('.', 1)
else:
@@ -138,7 +137,7 @@ def try_report_action(cr, uid, action_id, active_model=None, active_ids=None,
if datas.get('id',False):
context.update( {'active_id': datas.get('id',False), 'active_ids': datas.get('ids',[]), 'active_model': datas.get('model',False)})
context1 = action.get('context', {})
- if isinstance(context1, basestring):
+ if isinstance(context1, pycompat.string_types):
context1 = safe_eval(context1, dict(context))
context.update(context1)
env = env(context=context)