-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Zip Download: Handle duplicate filenames
- Loading branch information
Showing
2 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from collections import defaultdict | ||
|
||
from filingcabinet.views import ensure_unique_filename | ||
|
||
|
||
def test_ensure_unique_filename(): | ||
filename_counter = defaultdict(int) | ||
|
||
assert ensure_unique_filename(filename_counter, "file.pdf") == "file.pdf" | ||
assert ensure_unique_filename(filename_counter, "file.pdf") == "file-1.pdf" | ||
assert ensure_unique_filename(filename_counter, "file.pdf") == "file-2.pdf" | ||
assert ensure_unique_filename(filename_counter, "file.pdf") == "file-3.pdf" | ||
assert ensure_unique_filename(filename_counter, "dir/file.pdf") == "dir/file.pdf" | ||
assert ensure_unique_filename(filename_counter, "dir/file.pdf") == "dir/file-1.pdf" | ||
assert ensure_unique_filename(filename_counter, "dir/file.pdf") == "dir/file-2.pdf" | ||
assert ensure_unique_filename(filename_counter, "file-1.pdf") == "file-1-1.pdf" | ||
assert ensure_unique_filename(filename_counter, "file-4.pdf") == "file-4.pdf" | ||
assert ensure_unique_filename(filename_counter, "file.pdf") == "file-5.pdf" |