Test access to report execute
This commit is contained in:
1 parent
b32cbb18a9
commit
a75f6b3f9c
7 files changed
+68
-2
No files matched your search
+1
-1
@@ -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',
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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')
|
||||
@@ -0,0 +1 @@
|
||||
${user.name}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.action.report" id="test_report">
|
||||
<field name="name">Test Report</field>
|
||||
<field name="report_name">test.test_report</field>
|
||||
<field name="report">tests/report.txt</field>
|
||||
<field name="template_extension">txt</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -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()
|
||||
|
||||
@@ -6,6 +6,7 @@ xml:
|
||||
sequence.xml
|
||||
workflow.xml
|
||||
wizard.xml
|
||||
report.xml
|
||||
modelview.xml
|
||||
field_function.xml
|
||||
message.xml
|
||||
Reference in new issue
Block a user