Skip to content

Commit

Permalink
update test for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Nov 8, 2023
1 parent ff4e467 commit 895b33e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rethink/models/files/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import io
import os
import threading
import zipfile
from typing import List, Tuple, Optional

import pymongo.errors
Expand Down Expand Up @@ -63,7 +64,11 @@ def upload_obsidian_thread(
doc: dict,
max_file_size: int,
) -> None:
unzipped_files = unzip_file(zipped_file.file.read())
try:
unzipped_files = unzip_file(zipped_file.file.read())
except zipfile.BadZipFile:
__set_running_false(uid, const.Code.INVALID_FILE_TYPE, [zipped_file.filename])
return
filtered_files = {}
existed_filename2nid = doc["obsidian"].copy()
img_path_dict = {}
Expand Down
10 changes: 9 additions & 1 deletion tests/test_models_files_unzip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import unittest
from zipfile import ZipFile
from zipfile import ZipFile, BadZipFile

from rethink.models.files import unzip

Expand Down Expand Up @@ -47,3 +47,11 @@ def test_unzip_files(self):
for filename, data in extracted_files.items():
self.assertEqual(self.orig_data[filename], data["file"])
os.remove("test.zip")

def test_unzip_not_zip(self):
with open("test.zip", "wb") as f:
f.write(b"hello world")
with open("test.zip", "rb") as f:
with self.assertRaises(BadZipFile):
_ = unzip.unzip_file(f.read())
os.remove("test.zip")

0 comments on commit 895b33e

Please sign in to comment.