Fix breaking PBA file upload unit tests on windows.

The tests broke because `get` endpoint opened up the file handle which was not closed anywhere. The delete endpoint couldn't delete the file, since a process was using it.
This commit is contained in:
VakarisZ 2021-09-24 17:05:47 +03:00 committed by Mike Salvatore
parent 089158a976
commit 87809c46c1
1 changed files with 6 additions and 3 deletions

View File

@ -92,16 +92,19 @@ def test_pba_file_upload_endpoint(
content_type="multipart/form-data; " "boundary=---------------------------" "1", content_type="multipart/form-data; " "boundary=---------------------------" "1",
follow_redirects=True, follow_redirects=True,
) )
resp_get = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") resp_get = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py")
assert resp_get.status_code == 200
assert resp_get.data.decode() == "m0nk3y"
# Closing the response closes the file handle, else it can't be deleted
resp_get.close()
resp_delete = flask_client.delete( resp_delete = flask_client.delete(
f"/api/fileUpload/{pba_os}", data="test.py", content_type="text/plain;" f"/api/fileUpload/{pba_os}", data="test.py", content_type="text/plain;"
) )
resp_get_del = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py") resp_get_del = flask_client.get(f"/api/fileUpload/{pba_os}?load=test.py")
assert resp_post.status_code == 200 assert resp_post.status_code == 200
assert resp_get.status_code == 200
assert resp_get.data.decode() == "m0nk3y"
assert resp_delete.status_code == 200 assert resp_delete.status_code == 200
assert resp_get_del.status_code == 404 assert resp_get_del.status_code == 404