From e7e6a60246c28e1399f0fd626c73b4f16b04a995 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 25 Jul 2012 10:53:29 +1200 Subject: [PATCH] Nicer error for empty preview spec submission. --- libpathod/app.py | 5 +++++ libpathod/templates/request_preview.html | 1 - libpathod/templates/response_preview.html | 1 - test/test_app.py | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libpathod/app.py b/libpathod/app.py index 17be448dc..e93a898fa 100644 --- a/libpathod/app.py +++ b/libpathod/app.py @@ -82,12 +82,17 @@ def _preview(is_request): template = "response_preview.html" spec = request.args["spec"] + args = dict( spec = spec, section = "main", syntaxerror = None, error = None ) + if not spec.strip(): + args["error"] = "Can't parse an empty spec." + return render(template, **args) + try: if is_request: r = rparse.parse_request(app.config["pathod"].request_settings, spec) diff --git a/libpathod/templates/request_preview.html b/libpathod/templates/request_preview.html index fe8a03e9f..eaf78898c 100644 --- a/libpathod/templates/request_preview.html +++ b/libpathod/templates/request_preview.html @@ -7,7 +7,6 @@

Error: {{ syntaxerror }}

{{ marked }}
{% elif error %} -

Error

{{ error }}

{% else %}

Spec:

diff --git a/libpathod/templates/response_preview.html b/libpathod/templates/response_preview.html index 1b44e4808..2e1abcf44 100644 --- a/libpathod/templates/response_preview.html +++ b/libpathod/templates/response_preview.html @@ -7,7 +7,6 @@

Error: {{ syntaxerror }}

{{ marked }}
{% elif error %} -

Error

{{ error }}

{% else %}

Spec:

diff --git a/test/test_app.py b/test/test_app.py index 699c9c41a..da6431c9f 100644 --- a/test/test_app.py +++ b/test/test_app.py @@ -59,3 +59,7 @@ class TestApp(tutils.DaemonTests): assert r.status_code == 200 assert 'Request' in r.content + r = self.getpath("/request_preview", params=dict(spec="")) + assert r.status_code == 200 + assert 'empty spec' in r.content +