From a75f6b3f9caa251fb99e040ba9b93165689aeb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 12 Sep 2024 16:10:29 +0200 Subject: [PATCH] Test access to report execute --- trytond/setup.py | 2 +- trytond/trytond/report/report.py | 2 +- trytond/trytond/tests/report.py | 16 +++++++++++++ trytond/trytond/tests/report.txt | 1 + trytond/trytond/tests/report.xml | 13 +++++++++++ trytond/trytond/tests/test_report.py | 35 ++++++++++++++++++++++++++++ trytond/trytond/tests/tryton.cfg | 1 + 7 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 trytond/trytond/tests/report.py create mode 100644 trytond/trytond/tests/report.txt create mode 100644 trytond/trytond/tests/report.xml diff --git a/trytond/setup.py b/trytond/setup.py index 6d55e2090f..57b92daaca 100755 --- a/trytond/setup.py +++ b/trytond/setup.py @@ -81,7 +81,7 @@ setup(name=name, 'trytond.ir.ui': ['*.xml', '*.rng', '*.rnc'], 'trytond.res': [ 'tryton.cfg', '*.xml', '*.html', 'view/*.xml', 'locale/*.po'], - 'trytond.tests': ['tryton.cfg', '*.xml', 'forbidden.txt'], + 'trytond.tests': ['tryton.cfg', '*.xml', '*.txt'], }, scripts=[ 'bin/trytond', diff --git a/trytond/trytond/report/report.py b/trytond/trytond/report/report.py index 119d889e27..0c8681f631 100644 --- a/trytond/trytond/report/report.py +++ b/trytond/trytond/report/report.py @@ -271,7 +271,7 @@ class Report(URLMixin, PoolBase): records, len(action_report_name) + len(join_string))])) else: filename = action_report_name - return (oext, content, action_report.direct_print, filename) + return (oext, content, bool(action_report.direct_print), filename) @classmethod def _execute(cls, records, header, data, action): diff --git a/trytond/trytond/tests/report.py b/trytond/trytond/tests/report.py new file mode 100644 index 0000000000..85e7582cd7 --- /dev/null +++ b/trytond/trytond/tests/report.py @@ -0,0 +1,16 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +from trytond.pool import Pool +from trytond.report import Report + + +class TestReport(Report): + "Test Report" + __name__ = 'test.test_report' + + +def register(module): + Pool.register( + TestReport, + module=module, type_='report') diff --git a/trytond/trytond/tests/report.txt b/trytond/trytond/tests/report.txt new file mode 100644 index 0000000000..94ea913c9c --- /dev/null +++ b/trytond/trytond/tests/report.txt @@ -0,0 +1 @@ +${user.name} diff --git a/trytond/trytond/tests/report.xml b/trytond/trytond/tests/report.xml new file mode 100644 index 0000000000..227d9fe2ee --- /dev/null +++ b/trytond/trytond/tests/report.xml @@ -0,0 +1,13 @@ + + + + + + Test Report + test.test_report + tests/report.txt + txt + + + diff --git a/trytond/trytond/tests/test_report.py b/trytond/trytond/tests/test_report.py index 7f94429964..ffe0fc7914 100644 --- a/trytond/trytond/tests/test_report.py +++ b/trytond/trytond/tests/test_report.py @@ -2,6 +2,8 @@ # this repository contains the full copyright notices and license terms. import datetime +from trytond.model.exceptions import AccessError +from trytond.pool import Pool from trytond.report.report import Report from trytond.tests.test_tryton import ( TestCase, activate_module, with_transaction) @@ -29,6 +31,39 @@ class ReportTestCase(TestCase): format='%d %b %Y %I:%M %p'), "08 Jul 2020 01:30 PM"), + @with_transaction() + def test_execute(self): + "Execute report" + pool = Pool() + Report = pool.get('test.test_report', type='report') + + self.assertEqual( + Report.execute([], {}), + ('txt', 'Administrator\n', False, 'Test Report')) + + @with_transaction() + def test_execute_without_model_access(self): + "Execute report without model access" + pool = Pool() + Report = pool.get('test.test_report', type='report') + ModelAccess = pool.get('ir.model.access') + ModelAccess.create([{ + 'model': 'test.access', + 'perm_write': False, + }]) + + with self.assertRaises(AccessError): + Report.execute([], {'model': 'test.access'}) + + @with_transaction() + def test_execute_without_read_access(self): + "Execute report without read access" + pool = Pool() + Report = pool.get('test.test_report', type='report') + + with self.assertRaises(AccessError): + Report.execute([1], {'model': 'test.access'}) + def create_test_format_timedelta(i, in_, out): @with_transaction() diff --git a/trytond/trytond/tests/tryton.cfg b/trytond/trytond/tests/tryton.cfg index 3ccff9290e..3880607899 100644 --- a/trytond/trytond/tests/tryton.cfg +++ b/trytond/trytond/tests/tryton.cfg @@ -6,6 +6,7 @@ xml: sequence.xml workflow.xml wizard.xml + report.xml modelview.xml field_function.xml message.xml