Commit 51ea9f24 authored by Jérome Perrin's avatar Jérome Perrin

software/seleniumserver: port to python3

parent ef041e34
......@@ -19,4 +19,4 @@ md5sum = 9b41238f67ea8e12f8ea9590fd552b33
[template-selenium]
filename = instance-selenium.cfg.in
md5sum = 3e50d629307ca9f1381909102a52756d
md5sum = 9b4742e8a249aef38c7c8c12d74b0605
......@@ -316,10 +316,10 @@ recipe = slapos.recipe.template
output = $${directory:bin}/$${:_buildout_section_name_}
inline =
#!${buildout:executable}
import json, urllib, sys
import json, urllib.request, sys
api_url = sys.argv[1]
expected_node_count = int(sys.argv[2])
actual_node_count = json.load(urllib.urlopen(api_url))['slotCounts']['total']
actual_node_count = json.load(urllib.request.urlopen(api_url))['slotCounts']['total']
sys.exit(0 if expected_node_count == actual_node_count else 1)
......
......@@ -31,12 +31,12 @@ import multiprocessing
import os
import tempfile
import unittest
import urlparse
import urllib.parse
import base64
import hashlib
import logging
import contextlib
from BaseHTTPServer import BaseHTTPRequestHandler
from http.server import BaseHTTPRequestHandler
from io import BytesIO
......@@ -72,7 +72,7 @@ class WebServer(ManagedHTTPServer):
self.send_response(200)
self.end_headers()
self.wfile.write(
'''
b'''
<html>
<title>Test page</title>
<body>
......@@ -97,15 +97,15 @@ class WebServer(ManagedHTTPServer):
self.send_response(200)
self.end_headers()
file_data = 'no file'
if form.has_key('f'):
file_data = form['f'].file.read()
if 'f' in form:
file_data = form['f'].file.read().decode()
self.wfile.write(
'''
('''
<html>
<title>%s</title>
<div>%s</div>
</html>
''' % (form['q'].value, file_data))
''' % (form['q'].value, file_data)).encode())
log_message = logging.getLogger(__name__ + '.WebServer').info
......@@ -148,7 +148,7 @@ class BrowserCompatibilityMixin(WebServerMixin):
WebDriverWait(self.driver, 3).until(EC.title_is(self.id()))
def test_upload_file(self):
f = tempfile.NamedTemporaryFile(delete=False)
f = tempfile.NamedTemporaryFile(delete=False, mode='w')
f.write(self.id())
f.close()
self.addCleanup(lambda: os.remove(f.name))
......@@ -307,7 +307,7 @@ class TestFrontend(WebServerMixin, SeleniumServerTestCase):
parameter_dict = self.computer_partition.getConnectionParameterDict()
admin_url = parameter_dict['admin-url']
parsed = urlparse.urlparse(admin_url)
parsed = urllib.parse.urlparse(admin_url)
self.assertEqual('admin', parsed.username)
self.assertTrue(parsed.password)
......@@ -316,7 +316,7 @@ class TestFrontend(WebServerMixin, SeleniumServerTestCase):
def test_browser_use_hub(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
parsed = urlparse.urlparse(webdriver_url)
parsed = urllib.parse.urlparse(webdriver_url)
self.assertEqual('selenium', parsed.username)
self.assertTrue(parsed.password)
......@@ -343,7 +343,7 @@ class TestSSHServer(SeleniumServerTestCase):
def test_connect(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
ssh_url = parameter_dict['ssh-url']
parsed = urlparse.urlparse(ssh_url)
parsed = urllib.parse.urlparse(ssh_url)
self.assertEqual('ssh', parsed.scheme)
client = paramiko.SSHClient()
......@@ -359,9 +359,9 @@ class TestSSHServer(SeleniumServerTestCase):
with contextlib.closing(client):
client.connect(
username=urlparse.urlparse(ssh_url).username,
hostname=urlparse.urlparse(ssh_url).hostname,
port=urlparse.urlparse(ssh_url).port,
username=urllib.parse.urlparse(ssh_url).username,
hostname=urllib.parse.urlparse(ssh_url).hostname,
port=urllib.parse.urlparse(ssh_url).port,
pkey=self.ssh_key,
)
......@@ -378,7 +378,7 @@ class TestSSHServer(SeleniumServerTestCase):
# Paramiko does not allow to get the fingerprint as SHA256 easily yet
# https://github.com/paramiko/paramiko/pull/1103
self.assertEqual(
fingerprint,
fingerprint.encode(),
# XXX with sha256, we need to remove that trailing =
base64.b64encode(
hashlib.new(fingerprint_algorithm,
......@@ -386,15 +386,15 @@ class TestSSHServer(SeleniumServerTestCase):
channel = client.invoke_shell()
channel.settimeout(30)
received = ''
received = b''
while True:
r = channel.recv(1024)
if not r:
break
received += r
if 'Selenium Server.' in received:
if b'Selenium Server.' in received:
break
self.assertIn("Welcome to SlapOS Selenium Server.", received)
self.assertIn(b"Welcome to SlapOS Selenium Server.", received)
class TestFirefox52(
......
......@@ -30,4 +30,5 @@ extra =
proftpd ${slapos.test.proftpd-setup:setup}
repman ${slapos.test.repman-setup:setup}
restic-rest-server ${slapos.test.restic_rest_server-setup:setup}
seleniumserver ${slapos.test.seleniumserver-setup:setup}
theia ${slapos.test.theia-setup:setup}
......@@ -380,7 +380,6 @@ extra =
jscrawler ${slapos.test.jscrawler-setup:setup}
jstestnode ${slapos.test.jstestnode-setup:setup}
re6stnet ${slapos.test.re6stnet-setup:setup}
seleniumserver ${slapos.test.seleniumserver-setup:setup}
slapos-master ${slapos.test.slapos-master-setup:setup}
slaprunner ${slapos.test.slaprunner-setup:setup}
turnserver ${slapos.test.turnserver-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