Commit 26d8b85a authored by Jérome Perrin's avatar Jérome Perrin

software/cloudooo/test: port the tests to python3

parent 4590d41f
...@@ -45,7 +45,6 @@ setup(name=name, ...@@ -45,7 +45,6 @@ setup(name=name,
'slapos.cookbook', 'slapos.cookbook',
'slapos.libnetworkcache', 'slapos.libnetworkcache',
'requests', 'requests',
'six',
'PyPDF2', 'PyPDF2',
], ],
zip_safe=True, zip_safe=True,
......
############################################################################## ##############################################################################
# coding: utf-8
# #
# Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2020 Nexedi SA and Contributors. All Rights Reserved.
# #
...@@ -31,8 +30,8 @@ import csv ...@@ -31,8 +30,8 @@ import csv
import multiprocessing import multiprocessing
import os import os
import json import json
import six.moves.xmlrpc_client as xmlrpclib import xmlrpc.client as xmlrpclib
import six.moves.urllib.parse as urllib_parse import urllib.parse as urllib_parse
import ssl import ssl
import base64 import base64
import io import io
...@@ -63,6 +62,7 @@ class CloudOooTestCase(_CloudOooTestCase): ...@@ -63,6 +62,7 @@ class CloudOooTestCase(_CloudOooTestCase):
context=ssl_context, context=ssl_context,
allow_none=True, allow_none=True,
) )
self.addCleanup(self.server('close'))
def normalizeFontName(font_name): def normalizeFontName(font_name):
...@@ -111,16 +111,16 @@ class HTMLtoPDFConversionFontTestMixin: ...@@ -111,16 +111,16 @@ class HTMLtoPDFConversionFontTestMixin:
def test(self): def test(self):
actual_font_mapping_mapping = {} actual_font_mapping_mapping = {}
for font in self.expected_font_mapping: for font in self.expected_font_mapping:
src_html = ''' src_html = f'''
<style> <style>
p {{ font-family: "{font}"; font-size: 20pt; }} p {{ font-family: "{font}"; font-size: 20pt; }}
</style> </style>
<p>the quick brown fox jumps over the lazy dog.</p> <p>the quick brown fox jumps over the lazy dog.</p>
<p>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</p> <p>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</p>
'''.format(**locals()) '''
pdf_data = self._convert_html_to_pdf(src_html) pdf_data = self._convert_html_to_pdf(src_html)
pdf_reader = PyPDF2.PdfFileReader(io.BytesIO((pdf_data))) pdf_reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_data))
self.assertEqual( self.assertEqual(
self.pdf_producer, self.pdf_producer,
pdf_reader.getDocumentInfo()['/Producer']) pdf_reader.getDocumentInfo()['/Producer'])
...@@ -165,7 +165,7 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -165,7 +165,7 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
'Liberation Sans Narrow': 'LiberationSansNarrow', 'Liberation Sans Narrow': 'LiberationSansNarrow',
'Liberation Serif': 'LiberationSerif', 'Liberation Serif': 'LiberationSerif',
'Linux LibertineG': 'LiberationSans', 'Linux LibertineG': 'LiberationSans',
'OpenSymbol': set(['DejaVuSans', 'OpenSymbol']), 'OpenSymbol': {'DejaVuSans', 'OpenSymbol'},
'Palatino': 'LiberationSans', 'Palatino': 'LiberationSans',
'Roboto Black': 'LiberationSans', 'Roboto Black': 'LiberationSans',
'Roboto Condensed Light': 'LiberationSans', 'Roboto Condensed Light': 'LiberationSans',
...@@ -180,9 +180,9 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -180,9 +180,9 @@ class TestWkhtmlToPDF(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
} }
def _convert_html_to_pdf(self, src_html): def _convert_html_to_pdf(self, src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'pdf', 'pdf',
False, False,
...@@ -238,9 +238,9 @@ class TestLibreoffice(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase): ...@@ -238,9 +238,9 @@ class TestLibreoffice(HTMLtoPDFConversionFontTestMixin, CloudOooTestCase):
} }
def _convert_html_to_pdf(self, src_html): def _convert_html_to_pdf(self, src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'pdf', 'pdf',
).encode()) ).encode())
...@@ -251,10 +251,10 @@ class TestLibreOfficeTextConversion(CloudOooTestCase): ...@@ -251,10 +251,10 @@ class TestLibreOfficeTextConversion(CloudOooTestCase):
def test_html_to_text(self): def test_html_to_text(self):
self.assertEqual( self.assertEqual(
base64.decodestring( base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring( base64.encodebytes(
u'<html>héhé</html>'.encode('utf-8')).decode(), '<html>héhé</html>'.encode()).decode(),
'html', 'html',
'txt', 'txt',
).encode()), ).encode()),
...@@ -274,19 +274,18 @@ class TestLibreOfficeCluster(CloudOooTestCase): ...@@ -274,19 +274,18 @@ class TestLibreOfficeCluster(CloudOooTestCase):
global _convert_html_to_text global _convert_html_to_text
def _convert_html_to_text(src_html): def _convert_html_to_text(src_html):
return base64.decodestring( return base64.decodebytes(
self.server.convertFile( self.server.convertFile(
base64.encodestring(src_html.encode()).decode(), base64.encodebytes(src_html.encode()).decode(),
'html', 'html',
'txt', 'txt',
).encode()) ).encode())
pool = multiprocessing.Pool(5) pool = multiprocessing.Pool(5)
# TODO py3: use with pool with pool:
converted = pool.map(_convert_html_to_text, converted = pool.map(
_convert_html_to_text,
['<html><body>hello</body></html>'] * 100) ['<html><body>hello</body></html>'] * 100)
pool.terminate()
pool.join()
self.assertEqual(converted, [codecs.BOM_UTF8 + b'hello\n'] * 100) self.assertEqual(converted, [codecs.BOM_UTF8 + b'hello\n'] * 100)
...@@ -294,9 +293,8 @@ class TestLibreOfficeCluster(CloudOooTestCase): ...@@ -294,9 +293,8 @@ class TestLibreOfficeCluster(CloudOooTestCase):
res = requests.get( res = requests.get(
urllib_parse.urljoin(self.url, '/haproxy;csv'), urllib_parse.urljoin(self.url, '/haproxy;csv'),
verify=False, verify=False,
stream=True,
) )
reader = csv.DictReader(res.raw) reader = csv.DictReader(io.StringIO(res.text))
line_list = list(reader) line_list = list(reader)
# requests have been balanced # requests have been balanced
total_hrsp_2xx = { total_hrsp_2xx = {
......
...@@ -42,3 +42,6 @@ extra = ...@@ -42,3 +42,6 @@ extra =
seleniumserver ${slapos.test.seleniumserver-setup:setup} seleniumserver ${slapos.test.seleniumserver-setup:setup}
theia ${slapos.test.theia-setup:setup} theia ${slapos.test.theia-setup:setup}
turnserver ${slapos.test.turnserver-setup:setup} turnserver ${slapos.test.turnserver-setup:setup}
### WIP: python2 softwares tested with python3
cloudooo ${slapos.test.cloudooo-setup:setup}
...@@ -367,7 +367,6 @@ extra = ...@@ -367,7 +367,6 @@ extra =
# You should not add more lines here. # You should not add more lines here.
backupserver ${slapos.test.backupserver-setup:setup} backupserver ${slapos.test.backupserver-setup:setup}
beremiz-ide ${slapos.test.beremiz-ide-setup:setup} beremiz-ide ${slapos.test.beremiz-ide-setup:setup}
cloudooo ${slapos.test.cloudooo-setup:setup}
dream ${slapos.test.dream-setup:setup} dream ${slapos.test.dream-setup:setup}
gitlab ${slapos.test.gitlab-setup:setup} gitlab ${slapos.test.gitlab-setup:setup}
re6stnet ${slapos.test.re6stnet-setup:setup} re6stnet ${slapos.test.re6stnet-setup:setup}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment