This commit is contained in:
parent
fd3cab4035
commit
362b1b1363
|
@ -226,6 +226,38 @@ def test_get_folder_path_with_location():
|
||||||
|
|
||||||
assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
|
assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
|
||||||
|
|
||||||
|
def test_get_folder_path_with_int_in_source_path():
|
||||||
|
# gh-239
|
||||||
|
filesystem = FileSystem()
|
||||||
|
temporary_folder, folder = helper.create_working_folder('int')
|
||||||
|
|
||||||
|
origin = os.path.join(folder,'plain.jpg')
|
||||||
|
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||||
|
|
||||||
|
media = Photo(origin)
|
||||||
|
path = filesystem.get_folder_path(media.get_metadata())
|
||||||
|
|
||||||
|
assert path == os.path.join('2015-12-Dec','Unknown Location'), path
|
||||||
|
|
||||||
|
@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-path' % gettempdir())
|
||||||
|
def test_get_folder_path_with_int_in_config_component():
|
||||||
|
# gh-239
|
||||||
|
with open('%s/config.ini-int-in-path' % gettempdir(), 'w') as f:
|
||||||
|
f.write("""
|
||||||
|
[Directory]
|
||||||
|
date=%Y
|
||||||
|
full_path=%date
|
||||||
|
""")
|
||||||
|
if hasattr(load_config, 'config'):
|
||||||
|
del load_config.config
|
||||||
|
filesystem = FileSystem()
|
||||||
|
media = Photo(helper.get_file('plain.jpg'))
|
||||||
|
path = filesystem.get_folder_path(media.get_metadata())
|
||||||
|
if hasattr(load_config, 'config'):
|
||||||
|
del load_config.config
|
||||||
|
|
||||||
|
assert path == os.path.join('2015'), path
|
||||||
|
|
||||||
@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
|
@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
|
||||||
def test_get_folder_path_with_original_default_unknown_location():
|
def test_get_folder_path_with_original_default_unknown_location():
|
||||||
with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
|
with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
|
||||||
|
|
|
@ -27,9 +27,9 @@ def checksum(file_path, blocksize=65536):
|
||||||
return hasher.hexdigest()
|
return hasher.hexdigest()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def create_working_folder():
|
def create_working_folder(format=None):
|
||||||
temporary_folder = tempfile.gettempdir()
|
temporary_folder = tempfile.gettempdir()
|
||||||
folder = os.path.join(temporary_folder, random_string(10), random_string(10))
|
folder = os.path.join(temporary_folder, random_string(10, format), random_string(10, format))
|
||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
|
|
||||||
return (temporary_folder, folder)
|
return (temporary_folder, folder)
|
||||||
|
@ -81,8 +81,14 @@ def populate_folder(number_of_files, include_invalid=False):
|
||||||
|
|
||||||
return folder
|
return folder
|
||||||
|
|
||||||
def random_string(length):
|
def random_string(length, format=None):
|
||||||
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(length))
|
format_choice = string.ascii_uppercase + string.digits
|
||||||
|
if format == 'int':
|
||||||
|
format_choice = string.digits
|
||||||
|
elif format == 'str':
|
||||||
|
format_choice = string.asci_uppercase
|
||||||
|
|
||||||
|
return ''.join(random.SystemRandom().choice(format_choice) for _ in range(length))
|
||||||
|
|
||||||
def random_decimal():
|
def random_decimal():
|
||||||
return random.random()
|
return random.random()
|
||||||
|
|
Loading…
Reference in New Issue