Skip to content

Commit

Permalink
EDI Viewer: Checking files doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Aug 24, 2023
1 parent 5b22116 commit 4a86aea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions chellow/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,16 @@ def edi_viewer_get():
@home.route("/edi_viewer", methods=["POST"])
def edi_viewer_post():
segments = []
file_name = None
try:
if "edi_file" in request.values:
if "edi_file" in request.files:
file_item = req_file("edi_file")
edi_str = str(
file_item.stream.read(), encoding="utf-8-sig", errors="ignore"
)
file_name = file_item.filename
else:
edi_str = req_str("edi_fragment")
file_name = None

f = StringIO(edi_str)
f.seek(0)
Expand Down Expand Up @@ -723,8 +723,9 @@ def edi_viewer_post():
)
except BadRequest as e:
flash(e.description)
return render_template(
"edi_viewer.html", segments=segments, file_name=file_name
return make_response(
render_template("edi_viewer.html", segments=segments, file_name=file_name),
400,
)


Expand Down
13 changes: 13 additions & 0 deletions test/test_edi_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from io import BytesIO
from utils import match


def test_edit_viewer_post(client, mocker):
file_name = "sample.edi"
file_bytes = "MHD=1+UTLHDR:3'".encode("utf8")
f = BytesIO(file_bytes)

data = {"edi_file": (f, file_name)}
response = client.post("/edi_viewer", data=data)

match(response, 200)

0 comments on commit 4a86aea

Please sign in to comment.