Skip to content

Commit

Permalink
Fix bug with fallback values in full_path variables in config.ini (#234)
Browse files Browse the repository at this point in the history

* Add test for gh-234

* Force flush of cached configs in test
  • Loading branch information
ostavnaas authored and jmathai committed Aug 6, 2017
1 parent 00ba7e2 commit e5e811b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
4 changes: 1 addition & 3 deletions elodie/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,18 @@ def get_folder_path_definition(self):

self.cached_folder_path_definition = []
for part in path_parts:
part = part.replace('%', '')
if part in config_directory:
part = part[1:]
self.cached_folder_path_definition.append(
[(part, config_directory[part])]
)
elif part in self.default_parts:
part = part[1:]
self.cached_folder_path_definition.append(
[(part, '')]
)
else:
this_part = []
for p in part.split('|'):
p = p[1:]
this_part.append(
(p, config_directory[p] if p in config_directory else '')
)
Expand Down
37 changes: 36 additions & 1 deletion elodie/tests/filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,33 @@ def test_process_video_with_album_then_title():
assert origin_checksum != destination_checksum, destination_checksum
assert helper.path_tz_fix(os.path.join('2015-01-Jan','test_album','2015-01-19_12-45-11-movie-test_title.mov')) in destination, destination

@mock.patch('elodie.config.config_file', '%s/config.ini-fallback-folder' % gettempdir())
def test_process_file_fallback_folder():
with open('%s/config.ini-fallback-folder' % gettempdir(), 'w') as f:
f.write("""
[Directory]
date=%Y-%m
full_path=%date/%album|"fallback"
""")

if hasattr(load_config, 'config'):
del load_config.config
filesystem = FileSystem()
temporary_folder, folder = helper.create_working_folder()

origin = os.path.join(folder,'plain.jpg')
shutil.copyfile(helper.get_file('plain.jpg'), origin)

media = Photo(origin)
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
if hasattr(load_config, 'config'):
del load_config.config

assert helper.path_tz_fix(os.path.join('2015-12', 'fallback', '2015-12-05_00-59-26-plain.jpg')) in destination, destination

shutil.rmtree(folder)
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))

@mock.patch('elodie.config.config_file', '%s/config.ini-multiple-directories' % gettempdir())
def test_process_twice_more_than_two_levels_of_directories():
with open('%s/config.ini-multiple-directories' % gettempdir(), 'w') as f:
Expand All @@ -599,6 +626,8 @@ def test_process_twice_more_than_two_levels_of_directories():
full_path=%year/%month/%day
""")

if hasattr(load_config, 'config'):
del load_config.config
filesystem = FileSystem()
temporary_folder, folder = helper.create_working_folder()

Expand All @@ -607,12 +636,18 @@ def test_process_twice_more_than_two_levels_of_directories():

media = Photo(origin)
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
if hasattr(load_config, 'config'):
del load_config.config

assert helper.path_tz_fix(os.path.join('2015','12','05', '2015-12-05_00-59-26-plain.jpg')) in destination, destination

if hasattr(load_config, 'config'):
del load_config.config
media_second = Photo(destination)
media_second.set_title('foo')
destination_second = filesystem.process_file(destination, temporary_folder, media_second, allowDuplicate=True)
if hasattr(load_config, 'config'):
del load_config.config

assert destination.replace('.jpg', '-foo.jpg') == destination_second, destination_second

Expand Down Expand Up @@ -707,7 +742,7 @@ def test_get_folder_path_definition_default():
if hasattr(load_config, 'config'):
del load_config.config

assert path_definition == [[('date', '%Y-%m-%b')], [('album', ''), ('location', '%city'), ('Unknown Location"', '')]], path_definition
assert path_definition == [[('date', '%Y-%m-%b')], [('album', ''), ('location', '%city'), ('"Unknown Location"', '')]], path_definition

@mock.patch('elodie.config.config_file', '%s/config.ini-date-location' % gettempdir())
def test_get_folder_path_definition_date_location():
Expand Down

0 comments on commit e5e811b

Please sign in to comment.