mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[FIX] report_py3o: fix exception when report must be saved as attachement
The mehtod must be called with a list of ids not with a list of browse records
This commit is contained in:
committed by
Elmeri Niemelä
parent
3b00271ebb
commit
d29a3b3a8d
@@ -2,6 +2,7 @@
|
||||
# Copyright 2016 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).).
|
||||
|
||||
from base64 import b64decode
|
||||
import mock
|
||||
import os
|
||||
import pkg_resources
|
||||
@@ -88,6 +89,34 @@ class TestReportPy3o(TransactionCase):
|
||||
self.env.user.ids, report.report_name, {})
|
||||
self.assertEqual(('test result', 'pdf'), res)
|
||||
|
||||
def test_report_post_process(self):
|
||||
"""
|
||||
By default the post_process method is in charge to save the
|
||||
generated report into an ir.attachment if requested.
|
||||
"""
|
||||
report = self.env.ref("report_py3o.res_users_report_py3o")
|
||||
report.attachment = "object.name + '.txt'"
|
||||
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})
|
||||
ir_attachment = self.env['ir.attachment']
|
||||
attachements = ir_attachment.search([(1, '=', 1)])
|
||||
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)
|
||||
attachements = ir_attachment.search([(1, '=', 1)]) - attachements
|
||||
self.assertEqual(1, len(attachements.ids))
|
||||
self.assertEqual(self.env.user.name + '.txt', attachements.name)
|
||||
self.assertEqual(self.env.user._name, attachements.res_model)
|
||||
self.assertEqual(self.env.user.id, attachements.res_id)
|
||||
self.assertEqual('test result', b64decode(attachements.datas))
|
||||
|
||||
def test_report_template_configs(self):
|
||||
report = self.env.ref("report_py3o.res_users_report_py3o")
|
||||
# the demo template is specified with a relative path in in the module
|
||||
|
||||
Reference in New Issue
Block a user