diff options
Diffstat (limited to 'ewww.py')
-rw-r--r-- | ewww.py | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -1,2 +1,56 @@ +############################################################################# +# Some helpers to make step functions simpler. + +import json +import os +import re +import subprocess +import time + +import yaml + + +# Run a subprocess, capture its output and exit code in context. +def _run(ctx, argv): + p = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate("") + ctx['argv'] = argv + ctx['stdout'] = stdout.decode('utf-8') + ctx['stderr'] = stderr.decode('utf-8') + ctx['exit'] = p.returncode + + +# Check that latest call of _run ended with an specific exit code. +def _run_exit(ctx, expected): + assert_eq(ctx['exit'], expected) + + +# Write a file with given content. +def _write(filename, content): + open(filename, 'w').write(content) + + +############################################################################# +# The actual step functions. + + +# Fail: use this for unimplemented steps. def fixme(*args, **kwargs): - pass + assert 0 + +# Start server using named configuration file. +def start_server(ctx, filename=None): + _write(filename, get_file(filename).decode('UTF-8')) + 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() + _run_exit(ctx, 0) + +def request(ctx, method=None, url=None): + _run(ctx, ['curl', '-sv', '-X', method, url]) + _run_exit(ctx, 0) + +def status_code_is(ctx, code=None): + pattern = '\n< HTTP/1.1 {} '.format(code) + assert_eq(pattern in ctx['stderr'], True) |