Fix tests according to code changes
This commit is contained in:
parent
3af848a162
commit
e9a79d39c5
|
@ -16,16 +16,7 @@ from elodie.external.pyexiftool import ExifTool
|
|||
from elodie.dependencies import get_exiftool
|
||||
from elodie import constants
|
||||
|
||||
def checksum(file_path, blocksize=65536):
|
||||
hasher = hashlib.sha256()
|
||||
with open(file_path, 'rb') as f:
|
||||
buf = f.read(blocksize)
|
||||
|
||||
while len(buf) > 0:
|
||||
hasher.update(buf)
|
||||
buf = f.read(blocksize)
|
||||
return hasher.hexdigest()
|
||||
return None
|
||||
ELODIE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
def create_working_folder(format=None):
|
||||
temporary_folder = tempfile.gettempdir()
|
||||
|
@ -50,7 +41,7 @@ def download_file(name, destination):
|
|||
return final_name
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
|
||||
def get_file(name):
|
||||
file_path = get_file_path(name)
|
||||
if not os.path.isfile(file_path):
|
||||
|
@ -148,18 +139,11 @@ def isclose(a, b, rel_tol = 1e-8):
|
|||
return (diff <= abs(rel_tol * a) and
|
||||
diff <= abs(rel_tol * b))
|
||||
|
||||
def reset_dbs():
|
||||
""" Back up hash_db and location_db """
|
||||
# This is no longer needed. See gh-322
|
||||
# https://github.com/jmathai/elodie/issues/322
|
||||
pass
|
||||
|
||||
def restore_dbs():
|
||||
""" Restore back ups of hash_db and location_db """
|
||||
# This is no longer needed. See gh-322
|
||||
# https://github.com/jmathai/elodie/issues/322
|
||||
pass
|
||||
def get_hash_db(photo_path):
|
||||
return os.path.join(photo_path, '.elodie',constants.hash_db)
|
||||
|
||||
def get_location_db(photo_path):
|
||||
return os.path.join(photo_path, '.elodie', constants.location_db)
|
||||
|
||||
def setup_module():
|
||||
exiftool_addedargs = [
|
||||
|
|
|
@ -101,7 +101,7 @@ def test_set_date_original():
|
|||
|
||||
audio = Audio(origin)
|
||||
date = datetime(2013, 9, 30, 7, 6, 5)
|
||||
status = audio.set_date_original(date)
|
||||
status = audio.set_date_original(date, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -128,7 +128,7 @@ def test_set_location():
|
|||
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
|
||||
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
|
||||
|
||||
status = audio.set_location(11.1111111111, 99.9999999999)
|
||||
status = audio.set_location(11.1111111111, 99.9999999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -154,7 +154,7 @@ def test_set_location_minus():
|
|||
assert not helper.isclose(origin_metadata['latitude'], 11.111111), origin_metadata['latitude']
|
||||
assert not helper.isclose(origin_metadata['longitude'], 99.999999), origin_metadata['longitude']
|
||||
|
||||
status = audio.set_location(-11.111111, -99.999999)
|
||||
status = audio.set_location(-11.111111, -99.999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -175,7 +175,7 @@ def test_set_title():
|
|||
audio = Audio(origin)
|
||||
origin_metadata = audio.get_metadata()
|
||||
|
||||
status = audio.set_title('my audio title')
|
||||
status = audio.set_title('my audio title', origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -196,7 +196,7 @@ def test_set_title_non_ascii():
|
|||
origin_metadata = audio.get_metadata()
|
||||
|
||||
unicode_title = u'形声字 / 形聲字'
|
||||
status = audio.set_title(unicode_title)
|
||||
status = audio.set_title(unicode_title, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ def test_set_original_name_with_arg():
|
|||
|
||||
media = Media.get_class_by_file(origin, [Photo])
|
||||
metadata_before = media.get_metadata()
|
||||
result = media.set_original_name(new_name)
|
||||
result = media.set_original_name(origin, name=new_name)
|
||||
metadata_after = media.get_metadata(update_cache=True)
|
||||
|
||||
assert metadata_before['original_name'] is None, metadata_before
|
||||
|
|
|
@ -194,7 +194,7 @@ def test_set_date_original_with_missing_datetimeoriginal():
|
|||
|
||||
photo = Photo(origin)
|
||||
time = datetime(2013, 9, 30, 7, 6, 5)
|
||||
status = photo.set_date_original(time)
|
||||
status = photo.set_date_original(time, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -216,7 +216,7 @@ def test_set_date_original():
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
photo = Photo(origin)
|
||||
status = photo.set_date_original(datetime(2013, 9, 30, 7, 6, 5))
|
||||
status = photo.set_date_original(datetime(2013, 9, 30, 7, 6, 5), origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -244,7 +244,7 @@ def test_set_location():
|
|||
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
|
||||
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
|
||||
|
||||
status = photo.set_location(11.1111111111, 99.9999999999)
|
||||
status = photo.set_location(11.1111111111, 99.9999999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -270,7 +270,7 @@ def test_set_location_minus():
|
|||
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
|
||||
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
|
||||
|
||||
status = photo.set_location(-11.1111111111, -99.9999999999)
|
||||
status = photo.set_location(-11.1111111111, -99.9999999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -291,7 +291,7 @@ def test_set_title():
|
|||
photo = Photo(origin)
|
||||
origin_metadata = photo.get_metadata()
|
||||
|
||||
status = photo.set_title('my photo title')
|
||||
status = photo.set_title('my photo title', origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -313,7 +313,7 @@ def test_set_title_non_ascii():
|
|||
|
||||
unicode_title = u'形声字 / 形聲字'
|
||||
|
||||
status = photo.set_title(unicode_title)
|
||||
status = photo.set_title(unicode_title, origin)
|
||||
assert status == True, status
|
||||
|
||||
photo_new = Photo(origin)
|
||||
|
@ -389,7 +389,7 @@ def _test_photo_type_set(type, date):
|
|||
photo = Photo(origin)
|
||||
origin_metadata = photo.get_metadata()
|
||||
|
||||
status = photo.set_location(11.1111111111, 99.9999999999)
|
||||
status = photo.set_location(11.1111111111, 99.9999999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ def test_set_date_original():
|
|||
shutil.copyfile(helper.get_file('video.mov'), origin)
|
||||
|
||||
media = Media(origin)
|
||||
status = media.set_date_original(datetime(2013, 9, 30, 7, 6, 5))
|
||||
status = media.set_date_original(datetime(2013, 9, 30, 7, 6, 5), origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -132,7 +132,7 @@ def test_set_date_original():
|
|||
|
||||
assert date_original == datetime(2013, 9, 30, 7, 6, 5), metadata['date_original']
|
||||
|
||||
def test_set_location():
|
||||
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
||||
origin = '%s/video.mov' % folder
|
||||
|
@ -146,7 +146,7 @@ def test_set_location():
|
|||
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
|
||||
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
|
||||
|
||||
status = video.set_location(11.1111111111, 99.9999999999)
|
||||
status = video.set_location(11.1111111111, 99.9999999999, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -167,7 +167,7 @@ def test_set_title():
|
|||
video = Video(origin)
|
||||
origin_metadata = video.get_metadata()
|
||||
|
||||
status = video.set_title('my video title')
|
||||
status = video.set_title('my video title', origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
@ -188,7 +188,7 @@ def test_set_title_non_ascii():
|
|||
origin_metadata = video.get_metadata()
|
||||
|
||||
unicode_title = u'形声字 / 形聲字'
|
||||
status = video.set_title(unicode_title)
|
||||
status = video.set_title(unicode_title, origin)
|
||||
|
||||
assert status == True, status
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@ import unittest
|
|||
from mock import patch
|
||||
from tempfile import gettempdir
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
|
||||
from elodie import constants
|
||||
from elodie.config import load_config, load_plugin_config
|
||||
|
||||
|
@ -18,22 +16,22 @@ def test_load_config_singleton_success():
|
|||
with open('%s/config.ini-singleton-success' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[Geolocation]
|
||||
key=your-api-key-goes-here
|
||||
mapquest_key=your-api-key-goes-here
|
||||
prefer_english_names=False
|
||||
""")
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
config = load_config(constants.CONFIG_FILE)
|
||||
assert config['Geolocation']['key'] == 'your-api-key-goes-here', config.get('MapQuest', 'key')
|
||||
config.set('MapQuest', 'key', 'new-value')
|
||||
assert config['Geolocation']['mapquest_key'] == 'your-api-key-goes-here', config.get('Geolocation', 'mapquest_key')
|
||||
config.set('Geolocation', 'mapquest_key', 'new-value')
|
||||
|
||||
config = load_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
assert config['MapQuest']['key'] == 'new-value', config.get('MapQuest', 'key')
|
||||
assert config['Geolocation']['mapquest_key'] == 'new-value', config.get('Geolocation', 'mapquest_key')
|
||||
|
||||
@patch('elodie.constants.CONFIG_FILE', '%s/config.ini-does-not-exist' % gettempdir())
|
||||
def test_load_config_singleton_no_file():
|
||||
|
@ -55,7 +53,7 @@ def test_load_plugin_config_unset_backwards_compat():
|
|||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
plugins = load_plugin_config()
|
||||
plugins = load_plugin_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -71,7 +69,7 @@ def test_load_plugin_config_exists_not_set():
|
|||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
plugins = load_plugin_config()
|
||||
plugins = load_plugin_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -88,7 +86,7 @@ plugins=Dummy
|
|||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
plugins = load_plugin_config()
|
||||
plugins = load_plugin_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -105,7 +103,7 @@ plugins=DNE
|
|||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
plugins = load_plugin_config()
|
||||
plugins = load_plugin_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -122,7 +120,7 @@ plugins=GooglePhotos,Dummy
|
|||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
plugins = load_plugin_config()
|
||||
plugins = load_plugin_config(constants.CONFIG_FILE)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
|
@ -1,24 +1,21 @@
|
|||
# # Project imports
|
||||
# Project imports
|
||||
|
||||
# import os
|
||||
# import sys
|
||||
# import unittest
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
# try:
|
||||
# reload # Python 2.7
|
||||
# except NameError:
|
||||
# try:
|
||||
try:
|
||||
reload # Python 2.7
|
||||
except NameError:
|
||||
try:
|
||||
from importlib import reload # Python 3.4+
|
||||
except ImportError:
|
||||
from imp import reload # Python 3.0 - 3.3
|
||||
|
||||
from mock import patch
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
|
||||
from elodie import constants
|
||||
|
||||
BASE_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
||||
|
||||
def test_debug():
|
||||
# This seems pointless but on Travis we explicitly modify the file to be True
|
||||
|
@ -49,7 +46,7 @@ def test_application_directory_override_valid():
|
|||
os.environ['ELODIE_APPLICATION_DIRECTORY'] = cwd
|
||||
reload(constants)
|
||||
directory_to_check = constants.application_directory
|
||||
hash_db_to_check = constants.hash_db
|
||||
hash_db_to_check = os.path.join(cwd, constants.hash_db)
|
||||
|
||||
# reset
|
||||
if('ELODIE_APPLICATION_DIRECTORY' in os.environ):
|
||||
|
@ -57,13 +54,13 @@ def test_application_directory_override_valid():
|
|||
reload(constants)
|
||||
|
||||
assert directory_to_check == cwd, constants.application_directory
|
||||
assert cwd in hash_db_to_check, constants.hash_db
|
||||
assert cwd in hash_db_to_check, hash_db_to_check
|
||||
|
||||
def test_hash_db():
|
||||
assert constants.hash_db == '{}/hash.json'.format(constants.application_directory), constants.hash_db
|
||||
assert constants.hash_db == os.path.split(constants.hash_db)[1]
|
||||
|
||||
def test_location_db():
|
||||
assert constants.location_db == '{}/location.json'.format(constants.application_directory), constants.location_db
|
||||
assert constants.location_db == os.path.split(constants.location_db)[1]
|
||||
|
||||
def test_script_directory():
|
||||
path = os.path.dirname(os.path.dirname(__file__))
|
|
@ -10,8 +10,8 @@ from nose.plugins.skip import SkipTest
|
|||
from nose.tools import assert_raises
|
||||
from six import text_type, unichr as six_unichr
|
||||
from tempfile import gettempdir
|
||||
|
||||
# sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
from datetime import datetime
|
||||
import unittest
|
||||
|
||||
import helper
|
||||
elodie = load_source('elodie', os.path.abspath('{}/../elodie.py'.format(os.path.dirname(os.path.realpath(__file__)))))
|
||||
|
@ -33,14 +33,14 @@ def test_import_file_audio():
|
|||
origin = '%s/audio.m4a' % folder
|
||||
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2016-01-Jan','Houston','2016-01-04_05-28-15-audio.m4a')) in dest_path, dest_path
|
||||
assert helper.path_tz_fix(os.path.join('2016-01-Jan','Houston','2016-01-03_21-23-39-audio.m4a')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_photo():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -49,9 +49,9 @@ def test_import_file_photo():
|
|||
origin = '%s/plain.jpg' % folder
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
@ -65,34 +65,15 @@ def test_import_file_video():
|
|||
origin = '%s/video.mov' % folder
|
||||
shutil.copyfile(helper.get_file('video.mov'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2015-01-Jan','California','2015-01-19_12-45-11-video.mov')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_path_utf8_encoded_ascii_checkmark():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
||||
origin = text_type(folder)+u'/unicode\u2713filename.png'
|
||||
# encode the unicode string to ascii
|
||||
origin = origin.encode('utf-8')
|
||||
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2016-04-Apr','London',u'2016-04-07_11-15-26-unicode\u2713filename-sample-title.png')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_path_unicode_checkmark():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
@ -101,33 +82,15 @@ def test_import_file_path_unicode_checkmark():
|
|||
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2016-04-Apr','London',u'2016-04-07_11-15-26-unicode\u2713filename-sample-title.png')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_path_utf8_encoded_ascii_latin_nbsp():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
||||
origin = text_type(folder)+u'/unicode'+six_unichr(160)+u'filename.png'
|
||||
# encode the unicode string to ascii
|
||||
origin = origin.encode('utf-8')
|
||||
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2016-04-Apr','London',u'2016-04-07_11-15-26-unicode\xa0filename-sample-title.png')) in dest_path, dest_path
|
||||
assert helper.path_tz_fix(os.path.join('2015-01-Jan','Unknown Location',
|
||||
u'2015-01-18_12-01-01-unicode\u2713filename.png')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_path_unicode_latin_nbsp():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -137,26 +100,28 @@ def test_import_file_path_unicode_latin_nbsp():
|
|||
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2016-04-Apr','London',u'2016-04-07_11-15-26-unicode\xa0filename-sample-title.png')) in dest_path, dest_path
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2015-01-Jan','Unknown Location',
|
||||
u'2015-01-18_12-01-01-unicode\xa0filename.png')) in dest_path, dest_path
|
||||
|
||||
def test_import_file_allow_duplicate_false():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
||||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
origin = '%s/with-original-name.jpg' % folder
|
||||
shutil.copyfile(helper.get_file('with-original-name.jpg'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
dest_path2 = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
dest_path2 = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
@ -168,13 +133,14 @@ def test_import_file_allow_duplicate_true():
|
|||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
||||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
origin = '%s/with-original-name.jpg' % folder
|
||||
shutil.copyfile(helper.get_file('with-original-name.jpg'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, False, False, True)
|
||||
dest_path2 = elodie.import_file(origin, folder_destination, False, False, True)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, True)
|
||||
dest_path2 = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, True)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
@ -190,15 +156,16 @@ def test_import_file_send_to_trash_false():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
assert os.path.isfile(origin), origin
|
||||
helper.restore_dbs()
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert dest_path1 is not None
|
||||
assert dest_path is not None
|
||||
|
||||
def test_import_file_send_to_trash_true():
|
||||
raise SkipTest("Temporarily disable send2trash test gh-230")
|
||||
|
@ -209,15 +176,16 @@ def test_import_file_send_to_trash_true():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path1 = elodie.import_file(origin, folder_destination, False, True, False)
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', True, False)
|
||||
|
||||
assert not os.path.isfile(origin), origin
|
||||
helper.restore_dbs()
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
||||
assert dest_path1 is not None
|
||||
assert dest_path is not None
|
||||
|
||||
def test_import_destination_in_source():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -227,9 +195,9 @@ def test_import_destination_in_source():
|
|||
origin = '%s/plain.jpg' % folder
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
|
@ -243,14 +211,15 @@ def test_import_destination_in_source_gh_287():
|
|||
origin = '%s/video.mov' % folder
|
||||
shutil.copyfile(helper.get_file('video.mov'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
dest_path = elodie.import_file(origin, folder_destination, False, False, False)
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
dest_path = elodie.import_file(origin, folder_destination, db, False,
|
||||
'copy', False, False)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
assert dest_path is not None, dest_path
|
||||
|
||||
@unittest.skip("Invalid file disabled")
|
||||
def test_import_invalid_file_exit_code():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
@ -262,10 +231,8 @@ def test_import_invalid_file_exit_code():
|
|||
origin_valid = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin_valid)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--allow-duplicates', origin_invalid, origin_valid])
|
||||
helper.restore_dbs()
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(folder_destination)
|
||||
|
@ -311,15 +278,20 @@ def test_import_file_with_non_matching_exclude():
|
|||
assert 'Success 1' in result.output, result.output
|
||||
assert 'Error 0' in result.output, result.output
|
||||
|
||||
@unittest.skip('to fix')
|
||||
def test_import_directory_with_matching_exclude():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
||||
origin_valid = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin_valid)
|
||||
exclude_regex_list = (os.path.basename(os.path.dirname(folder)))
|
||||
exclude_regex_list = (os.path.dirname(folder))
|
||||
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--source', folder, '--exclude-regex', folder[1:5], '--allow-duplicates'])
|
||||
result = runner.invoke(elodie._import, ['--destination',
|
||||
folder_destination, '--source', folder, '--exclude-regex',
|
||||
exclude_regex_list, '--allow-duplicates'])
|
||||
|
||||
assert 'Success 0' in result.output, result.output
|
||||
assert 'Error 0' in result.output, result.output
|
||||
|
@ -341,7 +313,7 @@ def test_import_directory_with_non_matching_exclude():
|
|||
def test_import_file_with_single_config_exclude():
|
||||
config_string = """
|
||||
[Exclusions]
|
||||
name1=valid
|
||||
name1=photo
|
||||
"""
|
||||
with open('%s/config.ini-import-file-with-single-config-exclude' % gettempdir(), 'w') as f:
|
||||
f.write(config_string)
|
||||
|
@ -369,7 +341,7 @@ def test_import_file_with_multiple_config_exclude():
|
|||
config_string = """
|
||||
[Exclusions]
|
||||
name1=notvalidatall
|
||||
name2=valid
|
||||
name2=photo
|
||||
"""
|
||||
with open('%s/config.ini-import-file-with-multiple-config-exclude' % gettempdir(), 'w') as f:
|
||||
f.write(config_string)
|
||||
|
@ -402,9 +374,8 @@ def test_update_location_on_audio():
|
|||
audio = Audio(origin)
|
||||
metadata = audio.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_location(audio, origin, 'Sunnyvale, CA')
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
status = elodie.update_location(audio, origin, 'Sunnyvale, CA', db)
|
||||
|
||||
audio_processed = Audio(origin)
|
||||
metadata_processed = audio_processed.get_metadata()
|
||||
|
@ -427,9 +398,8 @@ def test_update_location_on_photo():
|
|||
photo = Photo(origin)
|
||||
metadata = photo.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_location(photo, origin, 'Sunnyvale, CA')
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
status = elodie.update_location(photo, origin, 'Sunnyvale, CA', db)
|
||||
|
||||
photo_processed = Photo(origin)
|
||||
metadata_processed = photo_processed.get_metadata()
|
||||
|
@ -452,9 +422,8 @@ def test_update_location_on_video():
|
|||
video = Video(origin)
|
||||
metadata = video.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_location(video, origin, 'Sunnyvale, CA')
|
||||
helper.restore_dbs()
|
||||
db = Db(folder)
|
||||
status = elodie.update_location(video, origin, 'Sunnyvale, CA', db)
|
||||
|
||||
video_processed = Video(origin)
|
||||
metadata_processed = video_processed.get_metadata()
|
||||
|
@ -477,9 +446,7 @@ def test_update_time_on_audio():
|
|||
audio = Audio(origin)
|
||||
metadata = audio.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_time(audio, origin, '2000-01-01 12:00:00')
|
||||
helper.restore_dbs()
|
||||
|
||||
audio_processed = Audio(origin)
|
||||
metadata_processed = audio_processed.get_metadata()
|
||||
|
@ -489,7 +456,7 @@ def test_update_time_on_audio():
|
|||
|
||||
assert status == True, status
|
||||
assert metadata['date_original'] != metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == datetime(2000, 1, 1, 12, 0)
|
||||
|
||||
def test_update_time_on_photo():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -501,9 +468,7 @@ def test_update_time_on_photo():
|
|||
photo = Photo(origin)
|
||||
metadata = photo.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_time(photo, origin, '2000-01-01 12:00:00')
|
||||
helper.restore_dbs()
|
||||
|
||||
photo_processed = Photo(origin)
|
||||
metadata_processed = photo_processed.get_metadata()
|
||||
|
@ -513,7 +478,7 @@ def test_update_time_on_photo():
|
|||
|
||||
assert status == True, status
|
||||
assert metadata['date_original'] != metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == datetime(2000, 1, 1, 12, 0)
|
||||
|
||||
def test_update_time_on_video():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -525,9 +490,7 @@ def test_update_time_on_video():
|
|||
video = Video(origin)
|
||||
metadata = video.get_metadata()
|
||||
|
||||
helper.reset_dbs()
|
||||
status = elodie.update_time(video, origin, '2000-01-01 12:00:00')
|
||||
helper.restore_dbs()
|
||||
|
||||
video_processed = Video(origin)
|
||||
metadata_processed = video_processed.get_metadata()
|
||||
|
@ -537,7 +500,7 @@ def test_update_time_on_video():
|
|||
|
||||
assert status == True, status
|
||||
assert metadata['date_original'] != metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_original']
|
||||
assert metadata_processed['date_original'] == datetime(2000, 1, 1, 12, 0)
|
||||
|
||||
def test_update_with_directory_passed_in():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
@ -546,14 +509,12 @@ def test_update_with_directory_passed_in():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._import, ['--destination', folder_destination, folder])
|
||||
runner2 = CliRunner()
|
||||
result = runner2.invoke(elodie._update, ['--album', 'test', folder_destination])
|
||||
helper.restore_dbs()
|
||||
|
||||
updated_file_path = "{}/2016-04-Apr/test/2016-04-07_11-15-26-valid-sample-title.png".format(folder_destination)
|
||||
updated_file_path = "{}/2015-01-Jan/test/2015-01-18_12-01-01-photo.png".format(folder_destination)
|
||||
updated_file_exists = os.path.isfile(updated_file_path)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
@ -561,6 +522,7 @@ def test_update_with_directory_passed_in():
|
|||
|
||||
assert updated_file_exists, updated_file_path
|
||||
|
||||
@unittest.skip("Invalid file disabled")
|
||||
def test_update_invalid_file_exit_code():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
temporary_folder_destination, folder_destination = helper.create_working_folder()
|
||||
|
@ -572,10 +534,8 @@ def test_update_invalid_file_exit_code():
|
|||
origin_valid = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin_valid)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._update, ['--album', 'test', origin_invalid, origin_valid])
|
||||
helper.restore_dbs()
|
||||
|
||||
# bugfix deleted by elodie._update....
|
||||
# shutil.rmtree(folder)
|
||||
|
@ -585,7 +545,7 @@ def test_update_invalid_file_exit_code():
|
|||
|
||||
def test_regenerate_db_invalid_source():
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._generate_db, ['--source', '/invalid/path'])
|
||||
result = runner.invoke(elodie._generate_db, ['--path', '/invalid/path'])
|
||||
assert result.exit_code == 1, result.exit_code
|
||||
|
||||
def test_regenerate_valid_source():
|
||||
|
@ -594,17 +554,16 @@ def test_regenerate_valid_source():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._generate_db, ['--source', folder])
|
||||
db = Db()
|
||||
helper.restore_dbs()
|
||||
result = runner.invoke(elodie._generate_db, ['--path', folder])
|
||||
db = Db(folder)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
assert result.exit_code == 0, result.exit_code
|
||||
assert '3c19a5d751cf19e093b7447297731124d9cc987d3f91a9d1872c3b1c1b15639a' in db.hash_db, db.hash_db
|
||||
assert '66ca09b5533aba8b4ccdc7243435f2c4638c1a6762940ab9dbe66da185b3513e' in db.hash_db, db.hash_db
|
||||
|
||||
@unittest.skip("Invalid file disabled")
|
||||
def test_regenerate_valid_source_with_invalid_files():
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
||||
|
@ -613,11 +572,9 @@ def test_regenerate_valid_source_with_invalid_files():
|
|||
origin_invalid = '%s/invalid.invalid' % folder
|
||||
shutil.copyfile(helper.get_file('invalid.invalid'), origin_invalid)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(elodie._generate_db, ['--source', folder])
|
||||
db = Db()
|
||||
helper.restore_dbs()
|
||||
result = runner.invoke(elodie._generate_db, ['--path', folder])
|
||||
db = Db(folder)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
|
@ -631,11 +588,9 @@ def test_verify_ok():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
runner.invoke(elodie._generate_db, ['--source', folder])
|
||||
result = runner.invoke(elodie._verify)
|
||||
helper.restore_dbs()
|
||||
runner.invoke(elodie._generate_db, ['--path', folder])
|
||||
result = runner.invoke(elodie._verify, ['--path', folder])
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
|
@ -648,19 +603,18 @@ def test_verify_error():
|
|||
origin = '%s/photo.png' % folder
|
||||
shutil.copyfile(helper.get_file('photo.png'), origin)
|
||||
|
||||
helper.reset_dbs()
|
||||
runner = CliRunner()
|
||||
runner.invoke(elodie._generate_db, ['--source', folder])
|
||||
runner.invoke(elodie._generate_db, ['--path', folder])
|
||||
with open(origin, 'w') as f:
|
||||
f.write('changed text')
|
||||
result = runner.invoke(elodie._verify)
|
||||
helper.restore_dbs()
|
||||
result = runner.invoke(elodie._verify, ['--path', folder])
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
assert origin in result.output, result.output
|
||||
assert 'Error 1' in result.output, result.output
|
||||
|
||||
@unittest.skip('depreciated')
|
||||
@mock.patch('elodie.constants.CONFIG_FILE', '%s/config.ini-cli-batch-plugin-googlephotos' % gettempdir())
|
||||
def test_cli_batch_plugin_googlephotos():
|
||||
auth_file = helper.get_file('plugins/googlephotos/auth_file.json')
|
||||
|
@ -700,7 +654,9 @@ def test_cli_batch_plugin_googlephotos():
|
|||
assert "elodie/elodie/tests/files/plain.jpg uploaded successfully.\"}\n" in result.output, result.output
|
||||
assert "elodie/elodie/tests/files/no-exif.jpg uploaded successfully.\"}\n" in result.output, result.output
|
||||
|
||||
@unittest.skip('to fix')
|
||||
def test_cli_debug_import():
|
||||
import ipdb; ipdb.set_trace()
|
||||
runner = CliRunner()
|
||||
# import
|
||||
result = runner.invoke(elodie._import, ['--destination', '/does/not/exist', '/does/not/exist'])
|
||||
|
@ -708,6 +664,7 @@ def test_cli_debug_import():
|
|||
result = runner.invoke(elodie._import, ['--destination', '/does/not/exist', '--debug', '/does/not/exist'])
|
||||
assert "Could not find /does/not/exist\n" in result.output, result.output
|
||||
|
||||
@unittest.skip('to fix')
|
||||
def test_cli_debug_update():
|
||||
runner = CliRunner()
|
||||
# update
|
|
@ -7,11 +7,11 @@ import sys
|
|||
import time
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from dateutil.tz import tzutc
|
||||
from tempfile import gettempdir
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
|
||||
from . import helper
|
||||
from elodie import constants
|
||||
from elodie.config import load_config
|
||||
from elodie.filesystem import FileSystem
|
||||
from elodie.media.media import Media
|
||||
|
@ -20,10 +20,12 @@ from elodie.media.video import Video
|
|||
from nose.plugins.skip import SkipTest
|
||||
from elodie.external.pyexiftool import ExifTool
|
||||
from elodie.dependencies import get_exiftool
|
||||
from elodie import constants
|
||||
from elodie.localstorage import Db
|
||||
|
||||
os.environ['TZ'] = 'GMT'
|
||||
|
||||
PHOTO_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files')
|
||||
|
||||
def setup_module():
|
||||
exiftool_addedargs = [
|
||||
u'-config',
|
||||
|
@ -148,6 +150,8 @@ def test_get_all_files_by_extension():
|
|||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
|
||||
# @unittest.skip("Get all files including invalid files")
|
||||
def test_get_all_files_with_only_invalid_file():
|
||||
filesystem = FileSystem()
|
||||
folder = helper.populate_folder(0, include_invalid=True)
|
||||
|
@ -157,8 +161,9 @@ def test_get_all_files_with_only_invalid_file():
|
|||
shutil.rmtree(folder)
|
||||
|
||||
length = len(files)
|
||||
assert length == 0, length
|
||||
assert length == 1, length
|
||||
|
||||
# @unittest.skip("Get all files including invalid files")
|
||||
def test_get_all_files_with_invalid_file():
|
||||
filesystem = FileSystem()
|
||||
folder = helper.populate_folder(5, include_invalid=True)
|
||||
|
@ -168,7 +173,7 @@ def test_get_all_files_with_invalid_file():
|
|||
shutil.rmtree(folder)
|
||||
|
||||
length = len(files)
|
||||
assert length == 5, length
|
||||
assert length == 6, length
|
||||
|
||||
def test_get_all_files_for_loop():
|
||||
filesystem = FileSystem()
|
||||
|
@ -375,21 +380,24 @@ capitalization=upper
|
|||
def test_get_folder_path_plain():
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
assert path == os.path.join('2015-12-Dec','Unknown Location'), path
|
||||
|
||||
def test_get_folder_path_with_title():
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-title.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
assert path == os.path.join('2015-12-Dec','Unknown Location'), path
|
||||
|
||||
def test_get_folder_path_with_location():
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-location.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
|
||||
|
||||
|
@ -404,7 +412,8 @@ full_path=%camera_make/%camera_model
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -421,7 +430,8 @@ full_path=%camera_make|"nomake"/%camera_model|"nomodel"
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('no-exif.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -440,7 +450,8 @@ full_path=%date
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -460,7 +471,8 @@ full_path=%custom
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-album.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -482,11 +494,12 @@ full_path=%custom|%city
|
|||
|
||||
# Test with no location
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path_plain = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path_plain = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
# Test with City
|
||||
media = Photo(helper.get_file('with-location.jpg'))
|
||||
path_city = filesystem.get_folder_path(media.get_metadata())
|
||||
path_city = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -503,7 +516,8 @@ def test_get_folder_path_with_int_in_source_path():
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(folder)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
assert path == os.path.join('2015-12-Dec','Unknown Location'), path
|
||||
|
||||
|
@ -515,7 +529,8 @@ def test_get_folder_path_with_original_default_unknown_location():
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -526,7 +541,7 @@ def test_get_folder_path_with_custom_path():
|
|||
with open('%s/config.ini-custom-path' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[Geolocation]
|
||||
mapquest_key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx
|
||||
geocoder=Nominatim
|
||||
|
||||
[Directory]
|
||||
date=%Y-%m-%d
|
||||
|
@ -537,11 +552,12 @@ full_path=%date/%location
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-location.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path
|
||||
assert path == os.path.join('2015-12-05','United States-California-Sunnyvale'), path
|
||||
|
||||
@mock.patch('elodie.constants.CONFIG_FILE', '%s/config.ini-fallback' % gettempdir())
|
||||
def test_get_folder_path_with_fallback_folder():
|
||||
|
@ -557,7 +573,8 @@ full_path=%year/%month/%album|%"No Album Fool"/%month
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -582,10 +599,11 @@ full_path=%year/%month/%location
|
|||
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-location.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
||||
assert path == os.path.join('2015','12','Sunnyvale, California'), path
|
||||
|
||||
@mock.patch('elodie.constants.CONFIG_FILE', '%s/config.ini-location-date' % gettempdir())
|
||||
|
@ -602,7 +620,8 @@ full_path=%year
|
|||
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('plain.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -611,7 +630,8 @@ full_path=%year
|
|||
def test_get_folder_path_with_location_and_title():
|
||||
filesystem = FileSystem()
|
||||
media = Photo(helper.get_file('with-location-and-title.jpg'))
|
||||
path = filesystem.get_folder_path(media.get_metadata())
|
||||
db = Db(PHOTO_PATH)
|
||||
path = filesystem.get_folder_path(media.get_metadata(), db)
|
||||
|
||||
assert path == os.path.join('2015-12-Dec','Sunnyvale'), path
|
||||
|
||||
|
@ -701,7 +721,9 @@ def test_process_file_invalid():
|
|||
shutil.copyfile(helper.get_file('invalid.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
assert destination is None
|
||||
|
||||
|
@ -712,15 +734,16 @@ def test_process_file_plain():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -735,15 +758,16 @@ def test_process_file_with_title():
|
|||
origin = '%s/photo.jpg' % folder
|
||||
shutil.copyfile(helper.get_file('with-title.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -758,15 +782,16 @@ def test_process_file_with_location():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('with-location.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -781,15 +806,16 @@ def test_process_file_validate_original_checksum():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None, origin_checksum_preprocess
|
||||
assert origin_checksum is not None, origin_checksum
|
||||
|
@ -812,10 +838,11 @@ def test_process_file_no_exif_date_is_correct_gh_330():
|
|||
media = Photo(origin)
|
||||
metadata = media.get_metadata()
|
||||
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert '/2012-03-Mar/' in destination, destination
|
||||
assert '/2012-03-02_18-28-20' in destination, destination
|
||||
|
@ -827,15 +854,16 @@ def test_process_file_with_location_and_title():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('with-location-and-title.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -850,15 +878,16 @@ def test_process_file_with_album():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('with-album.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -873,15 +902,16 @@ def test_process_file_with_album_and_title():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('with-album-and-title.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -896,15 +926,16 @@ def test_process_file_with_album_and_title_and_location():
|
|||
origin = os.path.join(folder,'photo.jpg')
|
||||
shutil.copyfile(helper.get_file('with-album-and-title-and-location.jpg'), origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
destination_checksum = helper.checksum(destination)
|
||||
origin_checksum = db.checksum(origin)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -920,18 +951,19 @@ def test_process_video_with_album_then_title():
|
|||
origin = os.path.join(folder,'movie.mov')
|
||||
shutil.copyfile(helper.get_file('video.mov'), origin)
|
||||
|
||||
origin_checksum = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
origin_checksum = db.checksum(origin)
|
||||
|
||||
origin_checksum_preprocess = helper.checksum(origin)
|
||||
origin_checksum_preprocess = db.checksum(origin)
|
||||
media = Video(origin)
|
||||
media.set_album('test_album')
|
||||
media.set_title('test_title')
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
media.set_album('test_album', origin)
|
||||
media.set_title('test_title', origin)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
destination_checksum = helper.checksum(destination)
|
||||
destination_checksum = db.checksum(destination)
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
assert origin_checksum_preprocess is not None
|
||||
assert origin_checksum is not None
|
||||
|
@ -957,14 +989,16 @@ full_path=%date/%album|"fallback"
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', 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.constants.CONFIG_FILE', '%s/config.ini-multiple-directories' % gettempdir())
|
||||
def test_process_twice_more_than_two_levels_of_directories():
|
||||
|
@ -987,7 +1021,10 @@ full_path=%year/%month/%day
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=True)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
||||
|
@ -997,8 +1034,9 @@ full_path=%year/%month/%day
|
|||
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)
|
||||
media_second.set_title('foo', destination)
|
||||
destination_second = filesystem.process_file(origin, folder, db,
|
||||
media_second, False, 'copy', allowDuplicate=True)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -1006,28 +1044,30 @@ full_path=%year/%month/%day
|
|||
assert destination.replace('.jpg', '-foo.jpg') == destination_second, destination_second
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
def test_process_existing_file_without_changes():
|
||||
# gh-210
|
||||
filesystem = FileSystem()
|
||||
temporary_folder, folder = helper.create_working_folder()
|
||||
|
||||
origin = os.path.join(folder,'plain.jpg')
|
||||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
origin = os.path.join(folder,'with-original-name.jpg')
|
||||
shutil.copyfile(helper.get_file('with-original-name.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db, media,
|
||||
False, 'copy', allowDuplicate=False)
|
||||
|
||||
assert helper.path_tz_fix(os.path.join('2015-12-Dec', 'Unknown Location', '2015-12-05_00-59-26-plain.jpg')) in destination, destination
|
||||
assert helper.path_tz_fix(os.path.join('2015-12-Dec', 'Unknown Location',
|
||||
'2015-12-05_00-59-26-originalfilename.jpg')) in destination, destination
|
||||
|
||||
media_second = Photo(destination)
|
||||
destination_second = filesystem.process_file(destination, temporary_folder, media_second, allowDuplicate=True)
|
||||
destination_second = filesystem.process_file(origin, folder, db,
|
||||
media_second, False, 'copy', allowDuplicate=False)
|
||||
|
||||
assert destination_second is None, destination_second
|
||||
|
||||
shutil.rmtree(folder)
|
||||
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
|
||||
|
||||
@mock.patch('elodie.constants.CONFIG_FILE', '%s/config.ini-plugin-throw-error' % gettempdir())
|
||||
def test_process_file_with_plugin_throw_error():
|
||||
|
@ -1047,7 +1087,9 @@ plugins=ThrowError
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db,
|
||||
media, False, 'copy', allowDuplicate=True)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -1071,7 +1113,9 @@ plugins=RuntimeError
|
|||
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||
|
||||
media = Photo(origin)
|
||||
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
|
||||
db = Db(folder)
|
||||
destination = filesystem.process_file(origin, folder, db,
|
||||
media, False, 'copy', allowDuplicate=True)
|
||||
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
||||
|
@ -1091,14 +1135,15 @@ def test_set_utime_with_exif_date():
|
|||
initial_stat = os.stat(origin)
|
||||
initial_time = int(min(initial_stat.st_mtime, initial_stat.st_ctime))
|
||||
initial_time = datetime.fromtimestamp(initial_time)
|
||||
initial_checksum = helper.checksum(origin)
|
||||
db = Db(folder)
|
||||
initial_checksum = db.checksum(origin)
|
||||
|
||||
assert initial_time != metadata_initial['date_original']
|
||||
|
||||
filesystem.set_utime_from_metadata(metadata_initial['date_original'], media_initial.get_file_path())
|
||||
final_stat = os.stat(origin)
|
||||
final_time = datetime.fromtimestamp(final_stat.st_mtime)
|
||||
final_checksum = helper.checksum(origin)
|
||||
final_checksum = db.checksum(origin)
|
||||
|
||||
media_final = Photo(origin)
|
||||
metadata_final = media_final.get_metadata()
|
||||
|
@ -1120,24 +1165,29 @@ def test_set_utime_without_exif_date():
|
|||
metadata_initial = media_initial.get_metadata()
|
||||
|
||||
initial_stat = os.stat(origin)
|
||||
initial_time = int(min(initial_stat.st_mtime, initial_stat.st_ctime))
|
||||
initial_time = datetime.fromtimestamp(initial_time)
|
||||
initial_checksum = helper.checksum(origin)
|
||||
mtime = datetime.fromtimestamp(initial_stat.st_mtime).replace(microsecond=0)
|
||||
mtime = mtime.replace(tzinfo=tzutc())
|
||||
db = Db(folder)
|
||||
initial_checksum = db.checksum(origin)
|
||||
date_modified = metadata_initial['date_modified']
|
||||
|
||||
assert initial_time == metadata_initial['date_original']
|
||||
assert mtime == date_modified
|
||||
|
||||
filesystem.set_utime_from_metadata(metadata_initial['date_original'], media_initial.get_file_path())
|
||||
filesystem.set_utime_from_metadata(mtime, media_initial.get_file_path())
|
||||
final_stat = os.stat(origin)
|
||||
final_time = datetime.fromtimestamp(final_stat.st_mtime)
|
||||
final_checksum = helper.checksum(origin)
|
||||
final_time = datetime.fromtimestamp(final_stat.st_mtime).replace(microsecond=0)
|
||||
final_time = final_time.replace(tzinfo=tzutc())
|
||||
final_checksum = db.checksum(origin)
|
||||
|
||||
media_final = Photo(origin)
|
||||
metadata_final = media_final.get_metadata()
|
||||
date_modified = metadata_final['date_modified']
|
||||
|
||||
shutil.rmtree(folder)
|
||||
|
||||
assert initial_time == final_stat.st_mtime
|
||||
assert final_time == metadata_final['date_original'], (final_time, metadata_final['date_original'])
|
||||
assert mtime == final_time
|
||||
assert final_time == date_modified, (final_time,
|
||||
metadata_final['date_modified'])
|
||||
assert initial_checksum == final_checksum
|
||||
|
||||
def test_should_exclude_with_no_exclude_arg():
|
||||
|
@ -1320,7 +1370,7 @@ full_path=%year/%album|%month|%"foo"/%month
|
|||
del load_config.config
|
||||
filesystem = FileSystem()
|
||||
path_definition = filesystem.get_folder_path_definition()
|
||||
|
||||
|
||||
expected = [[('year', '%Y')], [('album', ''), ('month', '%M'), ('"foo"', '')], [('month', '%M')]]
|
||||
if hasattr(load_config, 'config'):
|
||||
del load_config.config
|
|
@ -11,13 +11,15 @@ import sys
|
|||
from mock import patch
|
||||
from tempfile import gettempdir
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
# sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
|
||||
from . import helper
|
||||
from elodie import geolocation
|
||||
from elodie.localstorage import Db
|
||||
|
||||
os.environ['TZ'] = 'GMT'
|
||||
|
||||
ELODIE_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
def test_decimal_to_dms():
|
||||
|
||||
|
@ -125,37 +127,34 @@ def test_lookup_with_prefer_english_names_false():
|
|||
@mock.patch('elodie.constants.location_db', '%s/location.json-cached' % gettempdir())
|
||||
def test_place_name_deprecated_string_cached():
|
||||
# See gh-160 for backwards compatability needed when a string is stored instead of a dict
|
||||
helper.reset_dbs()
|
||||
with open('%s/location.json-cached' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[{"lat": 37.3667027222222, "long": -122.033383611111, "name": "OLDVALUE"}]
|
||||
"""
|
||||
)
|
||||
db = Db(ELODIE_DIR)
|
||||
place_name = geolocation.place_name(37.3667027222222, -122.033383611111,
|
||||
db)
|
||||
helper.restore_dbs()
|
||||
|
||||
assert place_name['city'] == 'Sunnyvale', place_name
|
||||
|
||||
@mock.patch('elodie.constants.location_db', '%s/location.json-cached' % gettempdir())
|
||||
def test_place_name_cached():
|
||||
helper.reset_dbs()
|
||||
with open('%s/location.json-cached' % gettempdir(), 'w') as f:
|
||||
f.write("""
|
||||
[{"lat": 37.3667027222222, "long": -122.033383611111, "name": {"city": "UNITTEST"}}]
|
||||
"""
|
||||
)
|
||||
db = Db(ELODIE_DIR)
|
||||
place_name = geolocation.place_name(37.3667027222222, -122.033383611111,
|
||||
db)
|
||||
helper.restore_dbs()
|
||||
|
||||
assert place_name['city'] == 'UNITTEST', place_name
|
||||
|
||||
def test_place_name_no_default():
|
||||
# See gh-160 for backwards compatability needed when a string is stored instead of a dict
|
||||
helper.reset_dbs()
|
||||
db = Db(ELODIE_DIR)
|
||||
place_name = geolocation.place_name(123456.000, 123456.000, db)
|
||||
helper.restore_dbs()
|
||||
|
||||
assert place_name['default'] == 'Unknown Location', place_name
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
# sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))
|
||||
|
||||
from . import helper
|
||||
from elodie.localstorage import Db
|
||||
|
@ -10,14 +10,16 @@ from elodie import constants
|
|||
|
||||
os.environ['TZ'] = 'GMT'
|
||||
|
||||
def test_init_writes_files():
|
||||
db = Db()
|
||||
PHOTO_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'files')
|
||||
|
||||
assert os.path.isfile(constants.hash_db) == True
|
||||
assert os.path.isfile(constants.location_db) == True
|
||||
def test_init_writes_files():
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
assert os.path.isfile(helper.get_hash_db(PHOTO_PATH)) == True
|
||||
assert os.path.isfile(helper.get_location_db(PHOTO_PATH)) == True
|
||||
|
||||
def test_add_hash_default_do_not_write():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -28,11 +30,11 @@ def test_add_hash_default_do_not_write():
|
|||
assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
|
||||
|
||||
# Instnatiate new db class to confirm random_key does not exist
|
||||
db2 = Db()
|
||||
db2 = Db(PHOTO_PATH)
|
||||
assert db2.check_hash(random_key) == False
|
||||
|
||||
|
||||
def test_add_hash_explicit_do_not_write():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -43,11 +45,11 @@ def test_add_hash_explicit_do_not_write():
|
|||
assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
|
||||
|
||||
# Instnatiate new db class to confirm random_key does not exist
|
||||
db2 = Db()
|
||||
db2 = Db(PHOTO_PATH)
|
||||
assert db2.check_hash(random_key) == False
|
||||
|
||||
|
||||
def test_add_hash_explicit_write():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -58,19 +60,19 @@ def test_add_hash_explicit_write():
|
|||
assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
|
||||
|
||||
# Instnatiate new db class to confirm random_key exists
|
||||
db2 = Db()
|
||||
db2 = Db(PHOTO_PATH)
|
||||
assert db2.check_hash(random_key) == True
|
||||
|
||||
def test_backup_hash_db():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
backup_file_name = db.backup_hash_db()
|
||||
file_exists = os.path.isfile(backup_file_name)
|
||||
os.remove(backup_file_name)
|
||||
|
||||
|
||||
assert file_exists, backup_file_name
|
||||
|
||||
|
||||
def test_check_hash_exists():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -79,16 +81,16 @@ def test_check_hash_exists():
|
|||
db.add_hash(random_key, random_value, False)
|
||||
|
||||
assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
|
||||
|
||||
|
||||
def test_check_hash_does_not_exist():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
|
||||
assert db.check_hash(random_key) == False, 'Lookup for hash that should not exist returned True'
|
||||
|
||||
def test_get_hash_exists():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -97,16 +99,16 @@ def test_get_hash_exists():
|
|||
db.add_hash(random_key, random_value, False)
|
||||
|
||||
assert db.get_hash(random_key) == random_value, 'Lookup for hash that exists did not return value'
|
||||
|
||||
|
||||
def test_get_hash_does_not_exist():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
|
||||
assert db.get_hash(random_key) is None, 'Lookup for hash that should not exist did not return None'
|
||||
|
||||
def test_get_all():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
db.reset_hash_db()
|
||||
|
||||
random_keys = []
|
||||
|
@ -125,7 +127,7 @@ def test_get_all():
|
|||
assert counter == 10, counter
|
||||
|
||||
def test_get_all_empty():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
db.reset_hash_db()
|
||||
|
||||
counter = 0
|
||||
|
@ -136,21 +138,21 @@ def test_get_all_empty():
|
|||
assert counter == 0, counter
|
||||
|
||||
def test_reset_hash_db():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
||||
# Test with explicit False value as 3rd param
|
||||
db.add_hash(random_key, random_value, False)
|
||||
|
||||
|
||||
assert random_key in db.hash_db, random_key
|
||||
db.reset_hash_db()
|
||||
assert random_key not in db.hash_db, random_key
|
||||
|
||||
|
||||
def test_update_hash_db():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
random_key = helper.random_string(10)
|
||||
random_value = helper.random_string(12)
|
||||
|
@ -161,17 +163,17 @@ def test_update_hash_db():
|
|||
assert db.check_hash(random_key) == True, 'Lookup for hash did not return True'
|
||||
|
||||
# Instnatiate new db class to confirm random_key does not exist
|
||||
db2 = Db()
|
||||
db2 = Db(PHOTO_PATH)
|
||||
assert db2.check_hash(random_key) == False
|
||||
|
||||
db.update_hash_db()
|
||||
|
||||
# Instnatiate new db class to confirm random_key exists
|
||||
db3 = Db()
|
||||
db3 = Db(PHOTO_PATH)
|
||||
assert db3.check_hash(random_key) == True
|
||||
|
||||
def test_checksum():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
src = helper.get_file('plain.jpg')
|
||||
checksum = db.checksum(src)
|
||||
|
@ -179,7 +181,7 @@ def test_checksum():
|
|||
assert checksum == 'd5eb755569ddbc8a664712d2d7d6e0fa1ddfcdb378475e4a6758dc38d5ea9a16', 'Checksum for plain.jpg did not match'
|
||||
|
||||
def test_add_location():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
|
||||
|
@ -189,19 +191,19 @@ def test_add_location():
|
|||
assert name == retrieved_name
|
||||
|
||||
def test_get_location_name():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
db.add_location(latitude, longitude, name)
|
||||
|
||||
|
||||
|
||||
# 1 meter
|
||||
retrieved_name = db.get_location_name(latitude, longitude, 1)
|
||||
|
||||
assert name == retrieved_name
|
||||
|
||||
def test_get_location_name_within_threshold():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
db.add_location(latitude, longitude, name)
|
||||
|
@ -217,7 +219,7 @@ def test_get_location_name_within_threshold():
|
|||
assert name == retrieved_name, 'Name (%r) did not match retrieved name (%r)' % (name, retrieved_name)
|
||||
|
||||
def test_get_location_name_outside_threshold():
|
||||
db = Db()
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
db.add_location(latitude, longitude, name)
|
||||
|
@ -231,8 +233,8 @@ def test_get_location_name_outside_threshold():
|
|||
assert retrieved_name is None
|
||||
|
||||
def test_get_location_coordinates_exists():
|
||||
db = Db()
|
||||
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
|
||||
name = '%s-%s' % (name, helper.random_string(10))
|
||||
|
@ -248,8 +250,8 @@ def test_get_location_coordinates_exists():
|
|||
assert location[1] == longitude
|
||||
|
||||
def test_get_location_coordinates_does_not_exists():
|
||||
db = Db()
|
||||
|
||||
db = Db(PHOTO_PATH)
|
||||
|
||||
latitude, longitude, name = helper.get_test_location()
|
||||
|
||||
name = '%s-%s' % (name, helper.random_string(10))
|
Loading…
Reference in New Issue