Commit 1f6f9899 authored by Jérome Perrin's avatar Jérome Perrin Committed by Léo-Paul Géneau

seleniumserver: use managed resources in tests

parent 31673681
...@@ -34,8 +34,10 @@ import unittest ...@@ -34,8 +34,10 @@ import unittest
import urlparse import urlparse
import base64 import base64
import hashlib import hashlib
import logging
import contextlib import contextlib
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from BaseHTTPServer import BaseHTTPRequestHandler
from io import BytesIO from io import BytesIO
import paramiko import paramiko
...@@ -48,30 +50,22 @@ from selenium.webdriver.support import expected_conditions as EC ...@@ -48,30 +50,22 @@ from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
from slapos.testing.utils import findFreeTCPPort, ImageComparisonTestCase from slapos.testing.utils import findFreeTCPPort, ImageComparisonTestCase, ManagedHTTPServer
setUpModule, SeleniumServerTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, SeleniumServerTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath( os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))) os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
class WebServerMixin(object):
"""Mixin class which provides a simple web server reachable at self.server_url class WebServer(ManagedHTTPServer):
""" class RequestHandler(BaseHTTPRequestHandler):
def setUp(self):
"""Start a minimal web server.
"""
class TestHandler(BaseHTTPRequestHandler):
"""Request handler for our test server. """Request handler for our test server.
The implemented server is: The implemented server is:
- submit q and you'll get a page with q as title - submit q and you'll get a page with q as title
- upload a file and the file content will be displayed in div.uploadedfile - upload a file and the file content will be displayed in div.uploadedfile
""" """
def log_message(self, *args, **kw):
if SeleniumServerTestCase._debug:
BaseHTTPRequestHandler.log_message(self, *args, **kw)
def do_GET(self): def do_GET(self):
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
...@@ -111,18 +105,14 @@ class WebServerMixin(object): ...@@ -111,18 +105,14 @@ class WebServerMixin(object):
</html> </html>
''' % (form['q'].value, file_data)) ''' % (form['q'].value, file_data))
super(WebServerMixin, self).setUp() log_message = logging.getLogger(__name__ + '.WebServer').info
ip = os.environ.get('SLAPOS_TEST_IPV4', '127.0.1.1')
port = findFreeTCPPort(ip)
server = HTTPServer((ip, port), TestHandler)
self.server_process = multiprocessing.Process(target=server.serve_forever)
self.server_process.start()
self.server_url = 'http://%s:%s/' % (ip, port)
def tearDown(self):
self.server_process.terminate() class WebServerMixin(object):
self.server_process.join() """Mixin class which provides a simple web server reachable at self.server_url
super(WebServerMixin, self).tearDown() """
def setUp(self):
self.server_url = self.getManagedResource('web_server', WebServer).url
class BrowserCompatibilityMixin(WebServerMixin): class BrowserCompatibilityMixin(WebServerMixin):
......
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