From e97cfb7d727d57ca0866f3849cd2a8347d1ebbef Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 16:51:01 +0200 Subject: [PATCH 1/3] Fix skip fusion on server when the fusion is local --- report_py3o/demo/.~lock.res_user.odt# | 1 - report_py3o/py3o_parser.py | 2 ++ report_py3o/tests/test_report_py3o.py | 22 +++++++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 report_py3o/demo/.~lock.res_user.odt# diff --git a/report_py3o/demo/.~lock.res_user.odt# b/report_py3o/demo/.~lock.res_user.odt# deleted file mode 100644 index 3f8e53eb..00000000 --- a/report_py3o/demo/.~lock.res_user.odt# +++ /dev/null @@ -1 +0,0 @@ -,lmi,nbacsonelmi,04.10.2016 15:56,file:///home/lmi/.config/libreoffice/4; \ No newline at end of file diff --git a/report_py3o/py3o_parser.py b/report_py3o/py3o_parser.py index b3f4380d..373c7718 100644 --- a/report_py3o/py3o_parser.py +++ b/report_py3o/py3o_parser.py @@ -166,6 +166,8 @@ class Py3oParser(report_sxw): "datadict": json.dumps(datadict), "image_mapping": "{}", } + if report_xml.py3o_is_local_fusion: + fields['skipfusion'] = '1' r = requests.post( report_xml.py3o_server_id.url, data=fields, files=files) if r.status_code != 200: diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py index c8afa04a..fb71d8e9 100644 --- a/report_py3o/tests/test_report_py3o.py +++ b/report_py3o/tests/test_report_py3o.py @@ -14,14 +14,14 @@ import openerp.tests 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) + report = self.env.ref("report_py3o.res_users_report_py3o") + with mock.patch('openerp.addons.report_py3o.py3o_parser.' + 'Py3oParser.create_single_pdf') as patched_pdf: + # test the call the the create method inside our custom parser + report.render_report(self.env.user.ids, + report.report_name, + {}) + self.assertEqual(1, patched_pdf.call_count) + res = report.render_report( + self.env.user.ids, report.report_name, {}) + self.assertTrue(res) From aa91d03d85e5cb3136c7ce09d8d1f0ff234c9061 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 17:35:54 +0200 Subject: [PATCH 2/3] Improve tests --- report_py3o/py3o_parser.py | 2 +- report_py3o/tests/test_report_py3o.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/report_py3o/py3o_parser.py b/report_py3o/py3o_parser.py index 373c7718..e32e1af4 100644 --- a/report_py3o/py3o_parser.py +++ b/report_py3o/py3o_parser.py @@ -180,7 +180,7 @@ class Py3oParser(report_sxw): # we do nice chunked reading from the network... chunk_size = 1024 with NamedTemporaryFile( - suffix=filetype.human_ext, + suffix=filetype, prefix='py3o-template-' ) as fd: for chunk in r.iter_content(chunk_size): diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py index fb71d8e9..ee0f594b 100644 --- a/report_py3o/tests/test_report_py3o.py +++ b/report_py3o/tests/test_report_py3o.py @@ -19,9 +19,21 @@ class TestReportPy3o(TransactionCase): 'Py3oParser.create_single_pdf') as patched_pdf: # test the call the the create method inside our custom parser report.render_report(self.env.user.ids, - report.report_name, - {}) + report.report_name, + {}) self.assertEqual(1, patched_pdf.call_count) res = report.render_report( self.env.user.ids, report.report_name, {}) self.assertTrue(res) + py3o_server = self.env['py3o.server'].create({"url": "http://dummy"}) + # check the call to the fusion server + report.write({"py3o_filetype": "pdf", + "py3o_server_id": py3o_server.id}) + with mock.patch('requests.post') as patched_post: + magick_response = mock.MagicMock() + magick_response.status_code = 200 + patched_post.return_value = magick_response + magick_response.iter_content.return_value = "test result" + res = report.render_report( + self.env.user.ids, report.report_name, {}) + self.assertEqual(('test result', '.pdf'), res) From 31f9301a3c990a3121197898902ded2648bc0ba9 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 18:11:41 +0200 Subject: [PATCH 3/3] Replace openerp element by odoo --- report_py3o/views/ir_report.xml | 4 ++-- report_py3o/views/menu.xml | 4 ++-- report_py3o/views/py3o_server.xml | 4 ++-- report_py3o/views/py3o_template.xml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/report_py3o/views/ir_report.xml b/report_py3o/views/ir_report.xml index f06b4468..8e923ec2 100644 --- a/report_py3o/views/ir_report.xml +++ b/report_py3o/views/ir_report.xml @@ -1,4 +1,4 @@ - + @@ -28,4 +28,4 @@ - + diff --git a/report_py3o/views/menu.xml b/report_py3o/views/menu.xml index 4f26473f..38388f30 100644 --- a/report_py3o/views/menu.xml +++ b/report_py3o/views/menu.xml @@ -1,8 +1,8 @@ - + - + diff --git a/report_py3o/views/py3o_server.xml b/report_py3o/views/py3o_server.xml index 45fa384b..8a9682d4 100644 --- a/report_py3o/views/py3o_server.xml +++ b/report_py3o/views/py3o_server.xml @@ -1,5 +1,5 @@ - + py3o.server.configuration.form.view @@ -39,4 +39,4 @@ parent="py3o_config_menu" action="py3o_server_configuration_action" /> - + diff --git a/report_py3o/views/py3o_template.xml b/report_py3o/views/py3o_template.xml index adc3a953..0ee57f37 100644 --- a/report_py3o/views/py3o_template.xml +++ b/report_py3o/views/py3o_template.xml @@ -1,5 +1,5 @@ - + py3o.template.configuration.search.view @@ -51,4 +51,4 @@ parent="py3o_config_menu" action="py3o_template_configuration_action" /> - +