From 22bff734d76e7b6ade07dc9681e08333731753ca Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 16:39:50 +0200 Subject: [PATCH] Add simple tests and fix call to fusion server --- report_py3o/__openerp__.py | 2 +- report_py3o/demo/.~lock.res_user.odt# | 1 + report_py3o/demo/report_py3o.xml | 28 ++++++++++++++++++++++++++ report_py3o/demo/res_user.odt | Bin 0 -> 8671 bytes report_py3o/i18n/fr.po | 2 +- report_py3o/models/ir_report.py | 16 +++++++-------- report_py3o/py3o_parser.py | 13 ++++++------ report_py3o/tests/__init__.py | 1 + report_py3o/tests/test_report_py3o.py | 27 +++++++++++++++++++++++++ report_py3o/views/ir_report.xml | 2 +- 10 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 report_py3o/demo/.~lock.res_user.odt# create mode 100644 report_py3o/demo/report_py3o.xml create mode 100644 report_py3o/demo/res_user.odt create mode 100644 report_py3o/tests/__init__.py create mode 100644 report_py3o/tests/test_report_py3o.py diff --git a/report_py3o/__openerp__.py b/report_py3o/__openerp__.py index b5b8d052..e86cc6fa 100644 --- a/report_py3o/__openerp__.py +++ b/report_py3o/__openerp__.py @@ -24,11 +24,11 @@ The py3o.template package is required; install it with: }, 'data': [ 'security/ir.model.access.csv', - 'views/menu.xml', 'views/py3o_template.xml', 'views/py3o_server.xml', 'views/ir_report.xml', + 'demo/report_py3o.xml', ], 'installable': True, } diff --git a/report_py3o/demo/.~lock.res_user.odt# b/report_py3o/demo/.~lock.res_user.odt# new file mode 100644 index 00000000..3f8e53eb --- /dev/null +++ b/report_py3o/demo/.~lock.res_user.odt# @@ -0,0 +1 @@ +,lmi,nbacsonelmi,04.10.2016 15:56,file:///home/lmi/.config/libreoffice/4; \ No newline at end of file diff --git a/report_py3o/demo/report_py3o.xml b/report_py3o/demo/report_py3o.xml new file mode 100644 index 00000000..b57342f1 --- /dev/null +++ b/report_py3o/demo/report_py3o.xml @@ -0,0 +1,28 @@ + + + + + + + Py3o Demo Report + ir.actions.report.xml + res.users + py3o_user_info + py3o + odt + + odt + report_py3o + demo/res_user.odt + + + + + + res.users + Py3o Demo Report + + + + diff --git a/report_py3o/demo/res_user.odt b/report_py3o/demo/res_user.odt new file mode 100644 index 0000000000000000000000000000000000000000..f0d66bb89cedef8090f8e9848f09df270517f5c2 GIT binary patch literal 8671 zcmd6MbzD?y*Y;4-0s_*ll+q#H-AH%m83tsA1|^gpx+J600B#n`fRND*Y(_HIs=APWZ|m;>^Cm)!+q7p9>mkBdc)g}4M)Q9+5T$5;X?IpV27FNNRh| zZcj*Jb#mgPjYwF%e#{4*;5}_GT2eDf0Oh?qCBqo7^n6Z-=@x-G{*x`RXtAvtthxbZ z<~%ARR2|^UbURW!Y-uUo=?f*-&~LNR>-^)sg83HqyVy*hXS&Hxz0)?H)O~t$ZRB_5 zD}C~m%<=zo+c;iD(wHk{uBK6?M>q|jD61y(M#?1VBjG_C6;7LZeOtn1>6;u1K%e!Hz0 zRseioYI|;J#A6p60%ll+pPpBR)~T?vm)MA;sVs-;Xy>)`C-2j!dwemuczQhex|dtc zAP#Fbp=>lXT&c?gbuv*Y-JR@Fl@h9^@qJ>JmrA^Ute79dOx`Odh!N!uvI*2o z0?T{IDS*RCWj*CUShgE$AE>MnCZ!>Ls1nIHUy5vloMSpEb4YmiJW%f$$1-%%EpQ)H zpSE?EkPa-;+}H@y-Ne+2E~PNg*H+?skYb?nX~sHO7}&>4_I}u0T1iLi%}Yuu@|->c z-3fjg69Tv|EiXiR<;!fv;!|&u^|K@P(UH1)-aIk!9%o1iC(EC%^s%cbo0DKCQnL5U z<(j>OOJ0>7m&Cfyt1tSGaPbL&| z_!469nRE82ZNpfpAeU=hmke_iag?wNFV3aJ(L5nJxzu|&J4Zeb4cPKd0{Xh~RC*^r zg5h7PNI@RC+gXh&V-Xrz)g2?>Mm+7`&+Nb(9`%)zyd6}OoUS}e4?}waJ}iL&!*RRo zxe|Jx^uGU?DgDx(bs9C@#0fCdW*bLA%u;4BdWf&J>10`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JsYGG7>To;O|ST2p|7s-wUn3qJFKR{(z_=cK@!T`km$byYcf}_f2i?hY2I1;ZK#i zUx7b=)ZI*l|1dQ4pC`tD#r^zM@MqBd4^Rgm@oN721MpYW&q4p@75-r=cmDeQ@GJ7> z%I|UgMihQnE+RVq8XW&dBEFM;FNXgh0RV0!;fH8Fxgg??0oBdX{{ScVR=5BF literal 0 HcmV?d00001 diff --git a/report_py3o/i18n/fr.po b/report_py3o/i18n/fr.po index 39653c67..171e2e55 100644 --- a/report_py3o/i18n/fr.po +++ b/report_py3o/i18n/fr.po @@ -102,7 +102,7 @@ msgid "No Py3o server configuration found" msgstr "Pas de configuration trouvée du serveur Py3o" #. module: report_py3o -#: field:ir.actions.report.xml,py3o_fusion_filetype:0 +#: field:ir.actions.report.xml,py3o_filetype:0 msgid "Output Format" msgstr "Format de sortie" diff --git a/report_py3o/models/ir_report.py b/report_py3o/models/ir_report.py index 7c9686c7..418b7105 100644 --- a/report_py3o/models/ir_report.py +++ b/report_py3o/models/ir_report.py @@ -19,17 +19,17 @@ class ReportXml(models.Model): _inherit = 'ir.actions.report.xml' @api.one - @api.constrains("py3o_fusion_filetype", "report_type") - def _check_py3o_fusion_filetype(self): - if self.report_type == "py3o" and not self.py3o_fusion_filetype: + @api.constrains("py3o_filetype", "report_type") + def _check_py3o_filetype(self): + if self.report_type == "py3o" and not self.py3o_filetype: raise ValidationError( "Field 'Output Format' is required for Py3O report") @api.one @api.constrains("py3o_is_local_fusion", "py3o_server_id", - "py3o_fusion_filetype") + "py3o_filetype") def _check_py3o_server_id(self): - is_native = Formats().get_format(self.py3o_fusion_filetype) + is_native = Formats().get_format(self.py3o_filetype) if ((not is_native or not self.py3o_is_local_fusion) and not self.py3o_server_id): raise ValidationError( @@ -37,7 +37,7 @@ class ReportXml(models.Model): "Please specify a Fusion Server") @api.model - def _get_py3o_fusion_filetypes(self): + def _get_py3o_filetypes(self): formats = Formats() names = formats.get_known_format_names() selections = [] @@ -48,8 +48,8 @@ class ReportXml(models.Model): selections.append((name, description)) return selections - py3o_fusion_filetype = fields.Selection( - selection="_get_py3o_fusion_filetypes", + py3o_filetype = fields.Selection( + selection="_get_py3o_filetypes", string="Output Format") py3o_template_id = fields.Many2one( 'py3o.template', diff --git a/report_py3o/py3o_parser.py b/report_py3o/py3o_parser.py index f3e9c687..b3f4380d 100644 --- a/report_py3o/py3o_parser.py +++ b/report_py3o/py3o_parser.py @@ -143,26 +143,27 @@ class Py3oParser(report_sxw): localcontext = parser_instance.localcontext if report_xml.py3o_is_local_fusion: template.render(localcontext) - input = out_stream.getvalue() + in_stream = out_stream + datadict = {} else: expressions = template.get_all_user_python_expression() py_expression = template.convert_py3o_to_python_ast(expressions) convertor = Py3oConvertor() data_struct = convertor(py_expression) - input = data_struct.render(localcontext) + datadict = data_struct.render(localcontext) - filetype = report_xml.py3o_fusion_filetype + filetype = report_xml.py3o_filetype is_native = Formats().get_format(filetype).native if is_native: - res = input + res = out_stream.getvalue() else: # Call py3o.server to render the template in the desired format in_stream.seek(0) files = { 'tmpl_file': in_stream, } fields = { - "targetformat": filetype.fusion_ext, - "datadict": json.dumps(input), + "targetformat": filetype, + "datadict": json.dumps(datadict), "image_mapping": "{}", } r = requests.post( diff --git a/report_py3o/tests/__init__.py b/report_py3o/tests/__init__.py new file mode 100644 index 00000000..13bc3247 --- /dev/null +++ b/report_py3o/tests/__init__.py @@ -0,0 +1 @@ +from . import test_report_py3o diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py new file mode 100644 index 00000000..c8afa04a --- /dev/null +++ b/report_py3o/tests/test_report_py3o.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).). + + +import mock + +from openerp.tests.common import TransactionCase +import openerp.tests + + +@openerp.tests.common.at_install(False) +@openerp.tests.common.post_install(True) +class TestReportPy3o(TransactionCase): + + def test_reports(self): + domain = [('report_type', '=', 'py3o'), + ('report_name', '=', 'py3o_user_info')] + reports = self.env['ir.actions.report.xml'].search(domain) + self.assertEqual(1, len(reports)) + for r in reports: + with mock.patch('openerp.addons.report_py3o.py3o_parser.' + 'Py3oParser.create_single_pdf') as patched_pdf: + r.render_report(self.env.user.ids, + r.report_name, + {}) + self.assertEqual(1, patched_pdf.call_count) diff --git a/report_py3o/views/ir_report.xml b/report_py3o/views/ir_report.xml index e3469464..f06b4468 100644 --- a/report_py3o/views/ir_report.xml +++ b/report_py3o/views/ir_report.xml @@ -14,7 +14,7 @@ attrs="{'invisible': [('report_type', '!=', 'py3o')]}"> - +