diff --git a/libpathod/app.py b/libpathod/app.py index 111fafe50..6478964cd 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -73,8 +73,8 @@ def onelog(lid): return render("onelog.html", section="log", alog=l, lid=lid) -@app.route('/preview') -def preview(): +@app.route('/response_preview') +def response_preview(): spec = request.args["spec"] args = dict( spec = spec, @@ -87,10 +87,33 @@ def preview(): except rparse.ParseException, v: args["syntaxerror"] = str(v) args["marked"] = v.marked() - return render("preview.html", **args) + return render("preview_response.html", **args) s = cStringIO.StringIO() r.preview_safe() r.serve(s, check=app.config["pathod"].check_size) args["output"] = utils.escape_unprintables(s.getvalue()) - return render("preview.html", **args) + return render("preview_response.html", **args) + + +@app.route('/request_preview') +def request_preview(): + spec = request.args["spec"] + args = dict( + spec = spec, + section = "main", + syntaxerror = None, + error = None + ) + try: + r = rparse.parse_request(app.config["pathod"].request_settings, spec) + except rparse.ParseException, v: + args["syntaxerror"] = str(v) + args["marked"] = v.marked() + return render("preview_request.html", **args) + + s = cStringIO.StringIO() + r.preview_safe() + r.serve(s, check=app.config["pathod"].check_size, host="example.com") + args["output"] = utils.escape_unprintables(s.getvalue()) + return render("preview_request.html", **args) diff --git a/libpathod/static/pathod.css b/libpathod/static/pathod.css index 3e24dd7df..ad67179af 100644 --- a/libpathod/static/pathod.css +++ b/libpathod/static/pathod.css @@ -1,14 +1,11 @@ - section { margin-top: 50px; - } .example { margin-top: 10px; margin-bottom: 10px; - } .terminal { diff --git a/libpathod/templates/index.html b/libpathod/templates/index.html index 268bc7a56..6702ea2a4 100644 --- a/libpathod/templates/index.html +++ b/libpathod/templates/index.html @@ -1,29 +1,33 @@ {% extends "frame.html" %} {% block body %} -{% include "previewform.html" %}
{{ marked }}+{% elif error %} +
{{ error }}
+{% else %} +{{ spec }}+ +
{{ output }}+ +{% endif %} +{% include "request_previewform.html" %} +{% endblock %} diff --git a/libpathod/templates/preview.html b/libpathod/templates/preview_response.html similarity index 90% rename from libpathod/templates/preview.html rename to libpathod/templates/preview_response.html index 4b5182d71..1b44e4808 100644 --- a/libpathod/templates/preview.html +++ b/libpathod/templates/preview_response.html @@ -19,5 +19,5 @@
{{ output }}{% endif %} -{% include "previewform.html" %} +{% include "response_previewform.html" %} {% endblock %} diff --git a/libpathod/templates/request_previewform.html b/libpathod/templates/request_previewform.html new file mode 100644 index 000000000..accb1631a --- /dev/null +++ b/libpathod/templates/request_previewform.html @@ -0,0 +1,4 @@ + diff --git a/libpathod/templates/previewform.html b/libpathod/templates/response_previewform.html similarity index 61% rename from libpathod/templates/previewform.html rename to libpathod/templates/response_previewform.html index 42502ba79..74b25ce12 100644 --- a/libpathod/templates/previewform.html +++ b/libpathod/templates/response_previewform.html @@ -1,5 +1,5 @@ - diff --git a/test/test_app.py b/test/test_app.py index 0b406ee02..b0d730af3 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -21,21 +21,40 @@ class TestApp(tutils.DaemonTests): assert self.getpath("/log/%s"%id).status_code == 200 assert self.getpath("/log/9999999").status_code == 404 - def test_preview(self): - r = self.getpath("/preview", params=dict(spec="200")) + def test_response_preview(self): + r = self.getpath("/response_preview", params=dict(spec="200")) assert r.status_code == 200 assert 'Response' in r.content - r = self.getpath("/preview", params=dict(spec="foo")) + r = self.getpath("/response_preview", params=dict(spec="foo")) assert r.status_code == 200 assert 'Error' in r.content - r = self.getpath("/preview", params=dict(spec="200:b@100m")) + r = self.getpath("/response_preview", params=dict(spec="200:b@100m")) assert r.status_code == 200 assert "too large" in r.content - r = self.getpath("/preview", params=dict(spec="200:b@5k")) + r = self.getpath("/response_preview", params=dict(spec="200:b@5k")) assert r.status_code == 200 assert 'Response' in r.content + def test_request_preview(self): + r = self.getpath("/request_preview", params=dict(spec="get:/")) + assert r.status_code == 200 + assert 'Request' in r.content + + r = self.getpath("/request_preview", params=dict(spec="foo")) + assert r.status_code == 200 + assert 'Error' in r.content + + r = self.getpath("/request_preview", params=dict(spec="get:/:b@100m")) + assert r.status_code == 200 + assert "too large" in r.content + + r = self.getpath("/request_preview", params=dict(spec="get:/:b@5k")) + assert r.status_code == 200 + assert 'Request' in r.content + + +