Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to 5.0 #9

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
dist: xenial
python:
- "2.7"
- "3.6"
before_script:
- sudo apt-get update
- sudo apt-get install -y openssl build-essential xorg libssl-dev libxrender-dev wget xvfb fontconfig cabextract xfonts-75dpi
Expand Down
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:license: BSD, see LICENSE for more details.
"""
from trytond.pool import Pool
from company import Company
from .company import Company


def register():
Expand Down
3 changes: 1 addition & 2 deletions company.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from trytond.pool import PoolMeta
from trytond.model import fields

__metaclass__ = PoolMeta
__all__ = ['Company']


class Company:
class Company(metaclass=PoolMeta):
__name__ = 'company.company'

header_html = fields.Text('Header Html')
Expand Down
6 changes: 2 additions & 4 deletions openlabs_report_webkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def render(cls, report, report_context):
Translation = pool.get('ir.translation')
Company = pool.get('company.company')

# Convert to str as buffer from DB is not supported by StringIO
report_content = (str(report.report_content) if report.report_content
else False)
report_content = report.report_content or False
if not report_content:
raise Exception('Error', 'Missing report file!')

Expand Down Expand Up @@ -194,4 +192,4 @@ def wkhtml_to_pdf(cls, data, options=None):
args += ' %s %s.pdf' % (file_name, file_name)
# Execute the command using executor
execute(args)
return open(file_name + '.pdf').read()
return open(file_name + '.pdf', 'rb').read()
19 changes: 11 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import re
import os
import time
import sys
import unittest
import ConfigParser
from configparser import ConfigParser
from setuptools import setup, Command


Expand Down Expand Up @@ -72,7 +72,7 @@ def run(self):
sys.exit(-1)


config = ConfigParser.ConfigParser()
config = ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
for key in ('depends', 'extras_depend', 'xml'):
Expand Down Expand Up @@ -135,10 +135,13 @@ def run(self):
'trytond.modules.%s' % MODULE,
],
package_data={
'trytond.modules.%s' % MODULE: info.get('xml', []) +
info.get('translation', []) +
['tryton.cfg', 'locale/*.po', 'tests/*.rst', 'reports/*.odt'] +
['view/*.xml'],
'trytond.modules.%s' % MODULE: info.get('xml', []) + info.get(
'translation', []
) + [
'tryton.cfg', 'locale/*.po', 'tests/*.rst', 'reports/*.odt'
] + [
'view/*.xml'
],
},
package_dir={
'openlabs_report_webkit': 'openlabs_report_webkit',
Expand All @@ -148,7 +151,7 @@ def run(self):
license='GPL-3',
install_requires=requires,
tests_require=[
'pyPDF', # Check if the resultant pdf has the same content
'PyPDF2', # Check if the resultant pdf has the same content
],
extras_require={
'weasyprint': ['weasyprint']
Expand Down
72 changes: 36 additions & 36 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import unittest
import tempfile

from pyPdf import PdfFileReader
import trytond.tests.test_tryton
from PyPDF2 import PdfFileReader
from trytond.transaction import Transaction
from trytond.tests.test_tryton import POOL, USER, with_transaction
from trytond.tests.test_tryton import activate_module, with_transaction, USER
from trytond.pool import Pool

from openlabs_report_webkit import ReportWebkit
Expand All @@ -40,17 +39,17 @@ class ReportTestCase(unittest.TestCase):
def setUp(self):
register()

trytond.tests.test_tryton.install_module('report_webkit')

self.Currency = POOL.get('currency.currency')
self.Company = POOL.get('company.company')
self.Party = POOL.get('party.party')
self.User = POOL.get('res.user')
activate_module('report_webkit')

def setup_defaults(self):
"""
Setup the defaults
"""
self.Currency = Pool().get('currency.currency')
self.Company = Pool().get('company.company')
self.Party = Pool().get('party.party')
self.User = Pool().get('res.user')

with Transaction().set_context(company=None):
self.usd, = self.Currency.create([{
'name': 'US Dollar',
Expand Down Expand Up @@ -80,8 +79,8 @@ def test_0010_render_report_xhtml(self):
'''
Render the report without PDF conversion
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
UserReport = Pool().get('res.user', type='report')
IRReport = Pool().get('ir.action.report')

self.setup_defaults()

Expand All @@ -90,24 +89,24 @@ def test_0010_render_report_xhtml(self):
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
'<h1>Hello, {{records[0].name}}!</h1>'
'report_content': memoryview(
'<h1>Hello, {{records[0].name}}!</h1>'.encode()
),
'extension': 'html',
}])
val = UserReport.execute([USER], {})
self.assertEqual(val[0], u'html')
self.assertEqual(val[0], 'html')
self.assertEqual(
str(val[1]), '<h1>Hello, Administrator!</h1>'
val[1], '<h1>Hello, Administrator!</h1>'.encode()
)

@with_transaction()
def test_0020_render_unicode(self):
'''
Render the report without PDF conversion but having unicode template
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
UserReport = Pool().get('res.user', type='report')
IRReport = Pool().get('ir.action.report')

self.setup_defaults()

Expand All @@ -116,25 +115,25 @@ def test_0020_render_unicode(self):
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
"<h1>Héllø, {{data['name']}}!</h1>"
'report_content': memoryview(
"<h1>Héllø, {{data['name']}}!</h1>".encode()
),
'extension': 'html',
}])

val = UserReport.execute([USER], {'name': u'Cédric'})
self.assertEqual(val[0], u'html')
val = UserReport.execute([USER], {'name': 'Cédric'})
self.assertEqual(val[0], 'html')
self.assertEqual(
str(val[1]), '<h1>Héllø, Cédric!</h1>'
val[1], '<h1>Héllø, Cédric!</h1>'.encode()
)

@with_transaction()
def test_0025_render_escaping(self):
'''
Ensure that escaping works
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
UserReport = Pool().get('res.user', type='report')
IRReport = Pool().get('ir.action.report')

self.setup_defaults()

Expand All @@ -143,25 +142,26 @@ def test_0025_render_escaping(self):
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
"<h1>Héllø, {{data['name']}}!</h1>"
'report_content': memoryview(
"<h1>Héllø, {{data['name']}}!</h1>".encode()
),
'extension': 'html',
}])

val = UserReport.execute([USER], {'name': u'<script></script>'})
self.assertEqual(val[0], u'html')
val = UserReport.execute([USER], {'name': '<script></script>'})
self.assertEqual(val[0], 'html')
self.assertEqual(
str(val[1]), '<h1>Héllø, &lt;script&gt;&lt;/script&gt;!</h1>'
val[1],
'<h1>Héllø, &lt;script&gt;&lt;/script&gt;!</h1>'.encode()
)

@with_transaction()
def test_0030_render_pdf(self):
'''
Render the report in PDF
'''
UserReport = POOL.get('res.user', type='report')
IRReport = POOL.get('ir.action.report')
UserReport = Pool().get('res.user', type='report')
IRReport = Pool().get('ir.action.report')

self.setup_defaults()

Expand All @@ -170,23 +170,23 @@ def test_0030_render_pdf(self):
'name': 'HTML Report',
'model': 'res.user',
'report_name': 'res.user',
'report_content': buffer(
"<h1>Héllø, {{data['name']}}!</h1>"
'report_content': memoryview(
"<h1>Héllø, {{data['name']}}!</h1>".encode()
),
'extension': 'pdf',
}])

# Set Pool.test as False as we need the report to be generated
# as PDF
Pool.test = False
val = UserReport.execute([USER], {'name': u'Cédric'})
self.assertEqual(val[0], u'pdf')
val = UserReport.execute([USER], {'name': 'Cédric'})
self.assertEqual(val[0], 'pdf')

# Revert Pool.test back to True for other tests to run normally
Pool.test = True

with tempfile.TemporaryFile() as file:
file.write(str(val[1]))
file.write(val[1])
pdf = PdfFileReader(file)

# Probably the only thing you can check from a shitty PDF
Expand Down
2 changes: 1 addition & 1 deletion tryton.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tryton]
version=4.0.1.1
version=5.0.0.0
depends:
company
xml:
Expand Down