diff options
Diffstat (limited to 'ewww.py')
-rw-r--r-- | ewww.py | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -6,6 +6,7 @@ import os import re import subprocess import time +import urllib.parse import yaml @@ -30,6 +31,15 @@ def _write(filename, content): open(filename, 'w').write(content) +# Construct a URL that points to server running on localhost by +# replacing the actual scheme and host with ones that work for test. +def _url(ctx, url): + c = urllib.parse.urlparse(url) + host = c[1] + c = ('http', 'localhost:{}'.format(ctx['port'])) + c[2:] + return urllib.parse.urlunparse(c), host + + ############################################################################# # The actual step functions. @@ -40,15 +50,19 @@ def fixme(*args, **kwargs): # Start server using named configuration file. def start_server(ctx, filename=None): - _write(filename, get_file(filename).decode('UTF-8')) + config = get_file(filename).decode('UTF-8') + ctx['config'] = yaml.safe_load(config) + _write(filename, config) pid = os.path.abspath('ewww.pid') bin = os.path.join(srcdir, 'target', 'debug', 'ewww') _run(ctx, ['/usr/sbin/daemonize', '-p', pid, bin, filename]) ctx['pid'] = open(pid).read() + ctx['port'] = 3030 _run_exit(ctx, 0) def request(ctx, method=None, url=None): - _run(ctx, ['curl', '-sv', '-X', method, url]) + url, host = _url(ctx, url) + _run(ctx, ['curl', '-sv', '-X', method, '-HHost: {}'.format(host), url]) _run_exit(ctx, 0) def status_code_is(ctx, code=None): |