Skip to content

Commit d4bc2c7

Browse files
committed
Migrated to 5.0
1 parent 934b473 commit d4bc2c7

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- "2.7"
3+
- "3.6"
44
before_script:
55
- sudo apt-get update
66
- sudo apt-get install -y openssl build-essential xorg libssl-dev libxrender-dev wget xvfb fontconfig cabextract xfonts-75dpi

__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:license: BSD, see LICENSE for more details.
77
"""
88
from trytond.pool import Pool
9-
from company import Company
9+
from .company import Company
1010

1111

1212
def register():

company.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from trytond.pool import PoolMeta
99
from trytond.model import fields
1010

11-
__metaclass__ = PoolMeta
1211
__all__ = ['Company']
1312

1413

15-
class Company:
14+
class Company(metaclass=PoolMeta):
1615
__name__ = 'company.company'
1716

1817
header_html = fields.Text('Header Html')

openlabs_report_webkit/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ def render(cls, report, report_context):
3535
Translation = pool.get('ir.translation')
3636
Company = pool.get('company.company')
3737

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

@@ -194,4 +192,4 @@ def wkhtml_to_pdf(cls, data, options=None):
194192
args += ' %s %s.pdf' % (file_name, file_name)
195193
# Execute the command using executor
196194
execute(args)
197-
return open(file_name + '.pdf').read()
195+
return open(file_name + '.pdf', 'rb').read()

setup.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# This file is part of Tryton. The COPYRIGHT file at the top level of
33
# this repository contains the full copyright notices and license terms.
44
import re
55
import os
66
import time
77
import sys
88
import unittest
9-
import ConfigParser
9+
from configparser import ConfigParser
1010
from setuptools import setup, Command
1111

1212

@@ -72,7 +72,7 @@ def run(self):
7272
sys.exit(-1)
7373

7474

75-
config = ConfigParser.ConfigParser()
75+
config = ConfigParser()
7676
config.readfp(open('tryton.cfg'))
7777
info = dict(config.items('tryton'))
7878
for key in ('depends', 'extras_depend', 'xml'):
@@ -135,10 +135,13 @@ def run(self):
135135
'trytond.modules.%s' % MODULE,
136136
],
137137
package_data={
138-
'trytond.modules.%s' % MODULE: info.get('xml', []) +
139-
info.get('translation', []) +
140-
['tryton.cfg', 'locale/*.po', 'tests/*.rst', 'reports/*.odt'] +
141-
['view/*.xml'],
138+
'trytond.modules.%s' % MODULE: info.get('xml', []) + info.get(
139+
'translation', []
140+
) + [
141+
'tryton.cfg', 'locale/*.po', 'tests/*.rst', 'reports/*.odt'
142+
] + [
143+
'view/*.xml'
144+
],
142145
},
143146
package_dir={
144147
'openlabs_report_webkit': 'openlabs_report_webkit',
@@ -148,7 +151,7 @@ def run(self):
148151
license='GPL-3',
149152
install_requires=requires,
150153
tests_require=[
151-
'pyPDF', # Check if the resultant pdf has the same content
154+
'PyPDF2', # Check if the resultant pdf has the same content
152155
],
153156
extras_require={
154157
'weasyprint': ['weasyprint']

tests/test_report.py

+36-36
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
import unittest
1111
import tempfile
1212

13-
from pyPdf import PdfFileReader
14-
import trytond.tests.test_tryton
13+
from PyPDF2 import PdfFileReader
1514
from trytond.transaction import Transaction
16-
from trytond.tests.test_tryton import POOL, USER, with_transaction
15+
from trytond.tests.test_tryton import activate_module, with_transaction, USER
1716
from trytond.pool import Pool
1817

1918
from openlabs_report_webkit import ReportWebkit
@@ -40,17 +39,17 @@ class ReportTestCase(unittest.TestCase):
4039
def setUp(self):
4140
register()
4241

43-
trytond.tests.test_tryton.install_module('report_webkit')
44-
45-
self.Currency = POOL.get('currency.currency')
46-
self.Company = POOL.get('company.company')
47-
self.Party = POOL.get('party.party')
48-
self.User = POOL.get('res.user')
42+
activate_module('report_webkit')
4943

5044
def setup_defaults(self):
5145
"""
5246
Setup the defaults
5347
"""
48+
self.Currency = Pool().get('currency.currency')
49+
self.Company = Pool().get('company.company')
50+
self.Party = Pool().get('party.party')
51+
self.User = Pool().get('res.user')
52+
5453
with Transaction().set_context(company=None):
5554
self.usd, = self.Currency.create([{
5655
'name': 'US Dollar',
@@ -80,8 +79,8 @@ def test_0010_render_report_xhtml(self):
8079
'''
8180
Render the report without PDF conversion
8281
'''
83-
UserReport = POOL.get('res.user', type='report')
84-
IRReport = POOL.get('ir.action.report')
82+
UserReport = Pool().get('res.user', type='report')
83+
IRReport = Pool().get('ir.action.report')
8584

8685
self.setup_defaults()
8786

@@ -90,24 +89,24 @@ def test_0010_render_report_xhtml(self):
9089
'name': 'HTML Report',
9190
'model': 'res.user',
9291
'report_name': 'res.user',
93-
'report_content': buffer(
94-
'<h1>Hello, {{records[0].name}}!</h1>'
92+
'report_content': memoryview(
93+
'<h1>Hello, {{records[0].name}}!</h1>'.encode()
9594
),
9695
'extension': 'html',
9796
}])
9897
val = UserReport.execute([USER], {})
99-
self.assertEqual(val[0], u'html')
98+
self.assertEqual(val[0], 'html')
10099
self.assertEqual(
101-
str(val[1]), '<h1>Hello, Administrator!</h1>'
100+
val[1], '<h1>Hello, Administrator!</h1>'.encode()
102101
)
103102

104103
@with_transaction()
105104
def test_0020_render_unicode(self):
106105
'''
107106
Render the report without PDF conversion but having unicode template
108107
'''
109-
UserReport = POOL.get('res.user', type='report')
110-
IRReport = POOL.get('ir.action.report')
108+
UserReport = Pool().get('res.user', type='report')
109+
IRReport = Pool().get('ir.action.report')
111110

112111
self.setup_defaults()
113112

@@ -116,25 +115,25 @@ def test_0020_render_unicode(self):
116115
'name': 'HTML Report',
117116
'model': 'res.user',
118117
'report_name': 'res.user',
119-
'report_content': buffer(
120-
"<h1>Héllø, {{data['name']}}!</h1>"
118+
'report_content': memoryview(
119+
"<h1>Héllø, {{data['name']}}!</h1>".encode()
121120
),
122121
'extension': 'html',
123122
}])
124123

125-
val = UserReport.execute([USER], {'name': u'Cédric'})
126-
self.assertEqual(val[0], u'html')
124+
val = UserReport.execute([USER], {'name': 'Cédric'})
125+
self.assertEqual(val[0], 'html')
127126
self.assertEqual(
128-
str(val[1]), '<h1>Héllø, Cédric!</h1>'
127+
val[1], '<h1>Héllø, Cédric!</h1>'.encode()
129128
)
130129

131130
@with_transaction()
132131
def test_0025_render_escaping(self):
133132
'''
134133
Ensure that escaping works
135134
'''
136-
UserReport = POOL.get('res.user', type='report')
137-
IRReport = POOL.get('ir.action.report')
135+
UserReport = Pool().get('res.user', type='report')
136+
IRReport = Pool().get('ir.action.report')
138137

139138
self.setup_defaults()
140139

@@ -143,25 +142,26 @@ def test_0025_render_escaping(self):
143142
'name': 'HTML Report',
144143
'model': 'res.user',
145144
'report_name': 'res.user',
146-
'report_content': buffer(
147-
"<h1>Héllø, {{data['name']}}!</h1>"
145+
'report_content': memoryview(
146+
"<h1>Héllø, {{data['name']}}!</h1>".encode()
148147
),
149148
'extension': 'html',
150149
}])
151150

152-
val = UserReport.execute([USER], {'name': u'<script></script>'})
153-
self.assertEqual(val[0], u'html')
151+
val = UserReport.execute([USER], {'name': '<script></script>'})
152+
self.assertEqual(val[0], 'html')
154153
self.assertEqual(
155-
str(val[1]), '<h1>Héllø, &lt;script&gt;&lt;/script&gt;!</h1>'
154+
val[1],
155+
'<h1>Héllø, &lt;script&gt;&lt;/script&gt;!</h1>'.encode()
156156
)
157157

158158
@with_transaction()
159159
def test_0030_render_pdf(self):
160160
'''
161161
Render the report in PDF
162162
'''
163-
UserReport = POOL.get('res.user', type='report')
164-
IRReport = POOL.get('ir.action.report')
163+
UserReport = Pool().get('res.user', type='report')
164+
IRReport = Pool().get('ir.action.report')
165165

166166
self.setup_defaults()
167167

@@ -170,23 +170,23 @@ def test_0030_render_pdf(self):
170170
'name': 'HTML Report',
171171
'model': 'res.user',
172172
'report_name': 'res.user',
173-
'report_content': buffer(
174-
"<h1>Héllø, {{data['name']}}!</h1>"
173+
'report_content': memoryview(
174+
"<h1>Héllø, {{data['name']}}!</h1>".encode()
175175
),
176176
'extension': 'pdf',
177177
}])
178178

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

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

188188
with tempfile.TemporaryFile() as file:
189-
file.write(str(val[1]))
189+
file.write(val[1])
190190
pdf = PdfFileReader(file)
191191

192192
# Probably the only thing you can check from a shitty PDF

tryton.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tryton]
2-
version=4.0.1.1
2+
version=5.0.0.0
33
depends:
44
company
55
xml:

0 commit comments

Comments
 (0)