Skip to content
Snippets Groups Projects
Verified Commit 8290555d authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix doubled dots in path_and_rename and add a test for it

As os.path.splitext returns the file extension
including a dot, adding an extra one is superfluous.
parent 692a99f1
No related branches found
No related tags found
1 merge request!337Fix doubled dots in path_and_rename and add a test for it
Pipeline #3127 failed
import re
from aleksis.core.util.core_helpers import path_and_rename
def test_path_and_rename():
re_base = r"[a-z0-9]+"
example_1 = "sdjaasjkl.jpg"
re_example_1 = "files/" + re_base + r"\.jpg"
re2_example_1 = "images/" + re_base + r"\.jpg"
assert re.match(re_example_1, path_and_rename(None, example_1))
assert re.match(re2_example_1, path_and_rename(None, example_1, upload_to="images"))
example_2 = "sdjaasjkl"
re_example_2 = "files/" + re_base
re2_example_2 = "images/" + re_base
assert re.match(re_example_2, path_and_rename(None, example_2))
assert re.match(re2_example_2, path_and_rename(None, example_2, upload_to="images"))
......@@ -308,7 +308,7 @@ def path_and_rename(instance, filename: str, upload_to: str = "files") -> str:
_, ext = os.path.splitext(filename)
# set filename as random string
new_filename = f"{uuid4().hex}.{ext}"
new_filename = f"{uuid4().hex}{ext}"
# Create upload directory if necessary
os.makedirs(os.path.join(settings.MEDIA_ROOT, upload_to), exist_ok=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment