From 6375b2394eab075af6e7488d343131dc99fd7c3b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 21 Jun 2022 03:55:42 +0300 Subject: Test the upload of zip files works as expected - Ensure errors respond with status code 400 - Ensure error messages are displayed for any invalid zip file that is uploaded. --- qc_app/entry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'qc_app') diff --git a/qc_app/entry.py b/qc_app/entry.py index c53648a..efcaf4e 100644 --- a/qc_app/entry.py +++ b/qc_app/entry.py @@ -55,7 +55,7 @@ def zip_file_errors(filepath, upload_dir) -> Tuple[str, ...]: if len(infolist) != 1: zfile_errors = zfile_errors + ( ("Expected exactly one (1) member file within the uploaded zip " - "file. Got {len(infolist)} member files."),) + f"file. Got {len(infolist)} member files."),) if len(infolist) == 1 and infolist[0].is_dir(): zfile_errors = zfile_errors + ( ("Expected a member text file in the uploaded zip file. Got a " @@ -82,7 +82,7 @@ def upload_file(): if request_errors: for error in request_errors: flash(error, "alert-error") - return render_template("index.html") + return render_template("index.html"), 400 filename = secure_filename(request.files["qc_text_file"].filename) if not os.path.exists(upload_dir): @@ -95,7 +95,7 @@ def upload_file(): if zip_errors: for error in zip_errors: flash(error, "alert-error") - return render_template("index.html") + return render_template("index.html"), 400 return redirect(url_for( "parse.parse", filename=filename, -- cgit v1.2.3