From bf0ef2c0831dbcb8509922a21f77c17fa8ed5c9a Mon Sep 17 00:00:00 2001 From: Alvin Duran Date: Fri, 6 Jan 2023 14:22:01 -0400 Subject: [PATCH] Handling missing storage_location in storage_prefix_path by returning the filename alone. This would be an expected results of not specifying a storage location. --- keg_storage/plugin.py | 2 +- keg_storage/tests/test_views.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/keg_storage/plugin.py b/keg_storage/plugin.py index e6fa2c4..8bd4b81 100644 --- a/keg_storage/plugin.py +++ b/keg_storage/plugin.py @@ -198,7 +198,7 @@ def storage_prefix_path(location, filename): """Join the location path with the filename to get the full object path""" if filename.startswith('.'): filename = filename[1:] - return '/'.join([location.value, filename]) + return '/'.join([location.value, filename]) if location else filename @staticmethod def storage_generate_filename(filename): diff --git a/keg_storage/tests/test_views.py b/keg_storage/tests/test_views.py index 0486020..252440e 100644 --- a/keg_storage/tests/test_views.py +++ b/keg_storage/tests/test_views.py @@ -204,6 +204,10 @@ def test_storage_prefix_path(self): assert ObjectView.storage_prefix_path(StorageLocation.folder1, '.foo.txt') == \ 'Folder-One/foo.txt' + def test_storage_prefix_path_none_location(self): + assert ObjectView.storage_prefix_path(None, 'foo.txt') == \ + 'foo.txt' + def test_storage_get_profile(self): assert ObjectView.storage_get_profile('storage.s3') == \ flask.current_app.storage.get_interface('storage.s3')