2016-04-21 07:23:57 +02:00
# Project imports
from imp import load_source
2017-04-01 12:56:29 +02:00
import mock
2016-04-21 07:23:57 +02:00
import os
import sys
import shutil
2016-12-13 08:54:33 +01:00
from click . testing import CliRunner
2016-04-21 07:23:57 +02:00
from nose . plugins . skip import SkipTest
2016-12-13 08:54:33 +01:00
from nose . tools import assert_raises
2016-12-26 17:20:12 +01:00
from six import text_type , unichr as six_unichr
2017-04-01 12:56:29 +02:00
from tempfile import gettempdir
2021-06-27 07:00:04 +02:00
from datetime import datetime
import unittest
2016-04-21 07:23:57 +02:00
import helper
2021-06-20 08:35:28 +02:00
elodie = load_source ( ' elodie ' , os . path . abspath ( ' {} /../elodie.py ' . format ( os . path . dirname ( os . path . realpath ( __file__ ) ) ) ) )
2016-04-21 07:23:57 +02:00
2017-04-01 12:56:29 +02:00
from elodie . config import load_config
2016-12-13 08:54:33 +01:00
from elodie . localstorage import Db
2016-04-22 04:12:25 +02:00
from elodie . media . audio import Audio
from elodie . media . photo import Photo
from elodie . media . video import Video
2019-07-12 09:40:38 +02:00
from elodie . plugins . plugins import Plugins
from elodie . plugins . googlephotos . googlephotos import GooglePhotos
2016-04-21 07:23:57 +02:00
os . environ [ ' TZ ' ] = ' GMT '
def test_import_file_audio ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /audio.m4a ' % folder
shutil . copyfile ( helper . get_file ( ' audio.m4a ' ) , origin )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2016-04-21 07:23:57 +02:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2021-06-27 07:00:04 +02:00
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
2016-04-21 07:23:57 +02:00
def test_import_file_photo ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /plain.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2016-04-21 07:23:57 +02:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert helper . path_tz_fix ( os . path . join ( ' 2015-12-Dec ' , ' Unknown Location ' , ' 2015-12-05_00-59-26-plain.jpg ' ) ) in dest_path , dest_path
def test_import_file_video ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /video.mov ' % folder
shutil . copyfile ( helper . get_file ( ' video.mov ' ) , origin )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2016-04-21 07:23:57 +02:00
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
2017-07-12 06:11:51 +02:00
def test_import_file_path_unicode_checkmark ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = text_type ( folder ) + u ' /unicode \u2713 filename.png '
2017-07-12 06:11:51 +02:00
2021-06-20 08:35:28 +02:00
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2017-07-12 06:11:51 +02:00
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2017-07-12 06:11:51 +02:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2021-06-27 07:00:04 +02:00
assert helper . path_tz_fix ( os . path . join ( ' 2015-01-Jan ' , ' Unknown Location ' ,
u ' 2015-01-18_12-01-01-unicode \u2713 filename.png ' ) ) in dest_path , dest_path
2017-01-08 23:43:01 +01:00
2017-07-12 06:11:51 +02:00
def test_import_file_path_unicode_latin_nbsp ( ) :
2017-01-08 23:43:01 +01:00
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = text_type ( folder ) + u ' /unicode ' + six_unichr ( 160 ) + u ' filename.png '
2017-01-08 23:43:01 +01:00
2021-06-20 08:35:28 +02:00
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2017-01-08 23:43:01 +01:00
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2017-01-08 23:43:01 +01:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2021-06-27 07:00:04 +02:00
assert helper . path_tz_fix ( os . path . join ( ' 2015-01-Jan ' , ' Unknown Location ' ,
u ' 2015-01-18_12-01-01-unicode \xa0 filename.png ' ) ) in dest_path , dest_path
2016-09-08 06:08:13 +02:00
def test_import_file_allow_duplicate_false ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-27 07:00:04 +02:00
origin = ' %s /with-original-name.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' with-original-name.jpg ' ) , origin )
2016-09-08 06:08:13 +02:00
2021-06-27 07:00:04 +02:00
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 )
2016-09-08 06:08:13 +02:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert dest_path1 is not None
assert dest_path2 is None
def test_import_file_allow_duplicate_true ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-27 07:00:04 +02:00
origin = ' %s /with-original-name.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' with-original-name.jpg ' ) , origin )
2016-09-08 06:08:13 +02:00
2021-06-27 07:00:04 +02:00
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 )
2016-09-08 06:08:13 +02:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert dest_path1 is not None
assert dest_path2 is not None
assert dest_path1 == dest_path2
2016-12-23 06:35:15 +01:00
def test_import_file_send_to_trash_false ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2016-12-23 06:35:15 +01:00
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2016-12-23 06:35:15 +01:00
assert os . path . isfile ( origin ) , origin
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2021-06-27 07:00:04 +02:00
assert dest_path is not None
2016-12-23 06:35:15 +01:00
def test_import_file_send_to_trash_true ( ) :
2017-07-12 06:04:28 +02:00
raise SkipTest ( " Temporarily disable send2trash test gh-230 " )
2016-12-23 06:35:15 +01:00
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2016-12-23 06:35:15 +01:00
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , True , False )
2016-12-23 06:35:15 +01:00
assert not os . path . isfile ( origin ) , origin
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2021-06-27 07:00:04 +02:00
assert dest_path is not None
2016-12-23 06:35:15 +01:00
2016-11-08 08:09:23 +01:00
def test_import_destination_in_source ( ) :
temporary_folder , folder = helper . create_working_folder ( )
folder_destination = ' {} /destination ' . format ( folder )
os . mkdir ( folder_destination )
2018-12-02 05:25:04 +01:00
origin = ' %s /plain.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2018-12-02 05:25:04 +01:00
shutil . rmtree ( folder )
assert dest_path is None , dest_path
def test_import_destination_in_source_gh_287 ( ) :
temporary_folder , folder = helper . create_working_folder ( )
folder_destination = ' {} -destination ' . format ( folder )
os . mkdir ( folder_destination )
2016-11-08 08:09:23 +01:00
origin = ' %s /video.mov ' % folder
shutil . copyfile ( helper . get_file ( ' video.mov ' ) , origin )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
dest_path = elodie . import_file ( origin , folder_destination , db , False ,
' copy ' , False , False )
2016-11-08 08:09:23 +01:00
shutil . rmtree ( folder )
2018-12-02 05:25:04 +01:00
assert dest_path is not None , dest_path
2016-11-08 08:09:23 +01:00
2021-06-27 07:00:04 +02:00
@unittest.skip ( " Invalid file disabled " )
2017-01-22 05:52:32 +01:00
def test_import_invalid_file_exit_code ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
# use a good and bad
origin_invalid = ' %s /invalid.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' invalid.jpg ' ) , origin_invalid )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2017-01-22 05:52:32 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
2019-10-28 04:19:51 +01:00
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --allow-duplicates ' , origin_invalid , origin_valid ] )
2017-01-22 05:52:32 +01:00
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert result . exit_code == 1 , result . exit_code
2019-10-28 04:19:51 +01:00
def test_import_file_with_single_exclude ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --exclude-regex ' , origin_valid [ 0 : 5 ] , ' --allow-duplicates ' , origin_valid ] )
assert ' Success 0 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
def test_import_file_with_multiple_exclude ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --exclude-regex ' , ' does not exist in path ' , ' --exclude-regex ' , origin_valid [ 0 : 5 ] , ' --allow-duplicates ' , origin_valid ] )
assert ' Success 0 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
def test_import_file_with_non_matching_exclude ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --exclude-regex ' , ' does not exist in path ' , ' --allow-duplicates ' , origin_valid ] )
assert ' Success 1 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
2021-06-27 07:00:04 +02:00
@unittest.skip ( ' to fix ' )
2019-10-28 04:19:51 +01:00
def test_import_directory_with_matching_exclude ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
2021-06-27 07:00:04 +02:00
exclude_regex_list = ( os . path . basename ( os . path . dirname ( folder ) ) )
exclude_regex_list = ( os . path . dirname ( folder ) )
2019-10-28 04:19:51 +01:00
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
result = runner . invoke ( elodie . _import , [ ' --destination ' ,
folder_destination , ' --source ' , folder , ' --exclude-regex ' ,
exclude_regex_list , ' --allow-duplicates ' ] )
2019-10-28 04:19:51 +01:00
assert ' Success 0 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
def test_import_directory_with_non_matching_exclude ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --source ' , folder , ' --exclude-regex ' , ' non-matching ' , ' --allow-duplicates ' ] )
assert ' Success 1 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
2021-04-16 20:02:14 +02:00
@mock.patch ( ' elodie.constants.CONFIG_FILE ' , ' %s /config.ini-import-file-with-single-config-exclude ' % gettempdir ( ) )
2019-10-28 04:19:51 +01:00
def test_import_file_with_single_config_exclude ( ) :
config_string = """
[ Exclusions ]
2021-06-27 07:00:04 +02:00
name1 = photo
2019-10-28 04:19:51 +01:00
"""
with open ( ' %s /config.ini-import-file-with-single-config-exclude ' % gettempdir ( ) , ' w ' ) as f :
f . write ( config_string )
if hasattr ( load_config , ' config ' ) :
del load_config . config
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --allow-duplicates ' , origin_valid , ' --debug ' ] )
if hasattr ( load_config , ' config ' ) :
del load_config . config
assert ' Success 0 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
2021-04-16 20:02:14 +02:00
@mock.patch ( ' elodie.constants.CONFIG_FILE ' , ' %s /config.ini-import-file-with-multiple-config-exclude ' % gettempdir ( ) )
2019-10-28 04:19:51 +01:00
def test_import_file_with_multiple_config_exclude ( ) :
config_string = """
[ Exclusions ]
name1 = notvalidatall
2021-06-27 07:00:04 +02:00
name2 = photo
2019-10-28 04:19:51 +01:00
"""
with open ( ' %s /config.ini-import-file-with-multiple-config-exclude ' % gettempdir ( ) , ' w ' ) as f :
f . write ( config_string )
if hasattr ( load_config , ' config ' ) :
del load_config . config
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2019-10-28 04:19:51 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , ' --allow-duplicates ' , origin_valid , ' --debug ' ] )
if hasattr ( load_config , ' config ' ) :
del load_config . config
assert ' Success 0 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
2016-04-22 04:12:25 +02:00
def test_update_location_on_audio ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /audio.m4a ' % folder
shutil . copyfile ( helper . get_file ( ' audio.m4a ' ) , origin )
audio = Audio ( origin )
metadata = audio . get_metadata ( )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
status = elodie . update_location ( audio , origin , ' Sunnyvale, CA ' , db )
2016-04-22 04:12:25 +02:00
audio_processed = Audio ( origin )
metadata_processed = audio_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2016-04-22 04:38:00 +02:00
assert status == True , status
2016-10-26 07:10:48 +02:00
assert metadata [ ' latitude ' ] != metadata_processed [ ' latitude ' ] , metadata_processed [ ' latitude ' ]
2016-06-21 20:19:40 +02:00
assert helper . isclose ( metadata_processed [ ' latitude ' ] , 37.36883 ) , metadata_processed [ ' latitude ' ]
2016-04-22 04:12:25 +02:00
assert helper . isclose ( metadata_processed [ ' longitude ' ] , - 122.03635 ) , metadata_processed [ ' longitude ' ]
def test_update_location_on_photo ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /plain.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin )
photo = Photo ( origin )
metadata = photo . get_metadata ( )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
status = elodie . update_location ( photo , origin , ' Sunnyvale, CA ' , db )
2016-04-22 04:12:25 +02:00
photo_processed = Photo ( origin )
metadata_processed = photo_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2016-04-22 04:38:00 +02:00
assert status == True , status
2016-04-22 04:12:25 +02:00
assert metadata [ ' latitude ' ] != metadata_processed [ ' latitude ' ]
assert helper . isclose ( metadata_processed [ ' latitude ' ] , 37.36883 ) , metadata_processed [ ' latitude ' ]
assert helper . isclose ( metadata_processed [ ' longitude ' ] , - 122.03635 ) , metadata_processed [ ' longitude ' ]
def test_update_location_on_video ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /video.mov ' % folder
shutil . copyfile ( helper . get_file ( ' video.mov ' ) , origin )
video = Video ( origin )
metadata = video . get_metadata ( )
2021-06-27 07:00:04 +02:00
db = Db ( folder )
status = elodie . update_location ( video , origin , ' Sunnyvale, CA ' , db )
2016-04-22 04:12:25 +02:00
video_processed = Video ( origin )
metadata_processed = video_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
2016-04-22 04:38:00 +02:00
assert status == True , status
2016-04-22 04:12:25 +02:00
assert metadata [ ' latitude ' ] != metadata_processed [ ' latitude ' ]
2016-06-21 20:19:40 +02:00
assert helper . isclose ( metadata_processed [ ' latitude ' ] , 37.36883 ) , metadata_processed [ ' latitude ' ]
2016-04-22 04:12:25 +02:00
assert helper . isclose ( metadata_processed [ ' longitude ' ] , - 122.03635 ) , metadata_processed [ ' longitude ' ]
2016-04-22 04:38:00 +02:00
def test_update_time_on_audio ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /audio.m4a ' % folder
shutil . copyfile ( helper . get_file ( ' audio.m4a ' ) , origin )
audio = Audio ( origin )
metadata = audio . get_metadata ( )
status = elodie . update_time ( audio , origin , ' 2000-01-01 12:00:00 ' )
audio_processed = Audio ( origin )
metadata_processed = audio_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert status == True , status
2021-06-20 08:35:28 +02:00
assert metadata [ ' date_original ' ] != metadata_processed [ ' date_original ' ]
2021-06-27 07:00:04 +02:00
assert metadata_processed [ ' date_original ' ] == datetime ( 2000 , 1 , 1 , 12 , 0 )
2016-04-22 04:38:00 +02:00
def test_update_time_on_photo ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /plain.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin )
photo = Photo ( origin )
metadata = photo . get_metadata ( )
status = elodie . update_time ( photo , origin , ' 2000-01-01 12:00:00 ' )
photo_processed = Photo ( origin )
metadata_processed = photo_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert status == True , status
2021-06-20 08:35:28 +02:00
assert metadata [ ' date_original ' ] != metadata_processed [ ' date_original ' ]
2021-06-27 07:00:04 +02:00
assert metadata_processed [ ' date_original ' ] == datetime ( 2000 , 1 , 1 , 12 , 0 )
2016-04-22 04:38:00 +02:00
def test_update_time_on_video ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
origin = ' %s /video.mov ' % folder
shutil . copyfile ( helper . get_file ( ' video.mov ' ) , origin )
video = Video ( origin )
metadata = video . get_metadata ( )
status = elodie . update_time ( video , origin , ' 2000-01-01 12:00:00 ' )
video_processed = Video ( origin )
metadata_processed = video_processed . get_metadata ( )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert status == True , status
2021-06-20 08:35:28 +02:00
assert metadata [ ' date_original ' ] != metadata_processed [ ' date_original ' ]
2021-06-27 07:00:04 +02:00
assert metadata_processed [ ' date_original ' ] == datetime ( 2000 , 1 , 1 , 12 , 0 )
2016-04-22 04:38:00 +02:00
2017-01-08 06:49:00 +01:00
def test_update_with_directory_passed_in ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2017-01-08 06:49:00 +01:00
runner = CliRunner ( )
result = runner . invoke ( elodie . _import , [ ' --destination ' , folder_destination , folder ] )
runner2 = CliRunner ( )
result = runner2 . invoke ( elodie . _update , [ ' --album ' , ' test ' , folder_destination ] )
2021-06-27 07:00:04 +02:00
updated_file_path = " {} /2015-01-Jan/test/2015-01-18_12-01-01-photo.png " . format ( folder_destination )
2017-01-08 06:49:00 +01:00
updated_file_exists = os . path . isfile ( updated_file_path )
shutil . rmtree ( folder )
shutil . rmtree ( folder_destination )
assert updated_file_exists , updated_file_path
2021-06-27 07:00:04 +02:00
@unittest.skip ( " Invalid file disabled " )
2017-01-22 05:52:32 +01:00
def test_update_invalid_file_exit_code ( ) :
temporary_folder , folder = helper . create_working_folder ( )
temporary_folder_destination , folder_destination = helper . create_working_folder ( )
# use a good and bad
origin_invalid = ' %s /invalid.jpg ' % folder
shutil . copyfile ( helper . get_file ( ' invalid.jpg ' ) , origin_invalid )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
2017-01-22 05:52:32 +01:00
shutil . copyfile ( helper . get_file ( ' plain.jpg ' ) , origin_valid )
runner = CliRunner ( )
result = runner . invoke ( elodie . _update , [ ' --album ' , ' test ' , origin_invalid , origin_valid ] )
2021-06-20 08:35:28 +02:00
# bugfix deleted by elodie._update....
# shutil.rmtree(folder)
2017-01-22 05:52:32 +01:00
shutil . rmtree ( folder_destination )
assert result . exit_code == 1 , result . exit_code
2016-12-13 08:54:33 +01:00
def test_regenerate_db_invalid_source ( ) :
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
result = runner . invoke ( elodie . _generate_db , [ ' --path ' , ' /invalid/path ' ] )
2016-12-13 08:54:33 +01:00
assert result . exit_code == 1 , result . exit_code
def test_regenerate_valid_source ( ) :
temporary_folder , folder = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2016-12-13 08:54:33 +01:00
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
result = runner . invoke ( elodie . _generate_db , [ ' --path ' , folder ] )
db = Db ( folder )
2016-12-13 08:54:33 +01:00
shutil . rmtree ( folder )
assert result . exit_code == 0 , result . exit_code
2021-06-27 07:00:04 +02:00
assert ' 66ca09b5533aba8b4ccdc7243435f2c4638c1a6762940ab9dbe66da185b3513e ' in db . hash_db , db . hash_db
2016-12-13 08:54:33 +01:00
2021-06-27 07:00:04 +02:00
@unittest.skip ( " Invalid file disabled " )
2016-12-13 08:54:33 +01:00
def test_regenerate_valid_source_with_invalid_files ( ) :
temporary_folder , folder = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin_valid = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin_valid )
2016-12-13 08:54:33 +01:00
origin_invalid = ' %s /invalid.invalid ' % folder
shutil . copyfile ( helper . get_file ( ' invalid.invalid ' ) , origin_invalid )
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
result = runner . invoke ( elodie . _generate_db , [ ' --path ' , folder ] )
db = Db ( folder )
2016-12-13 08:54:33 +01:00
shutil . rmtree ( folder )
assert result . exit_code == 0 , result . exit_code
2017-01-03 05:58:52 +01:00
assert ' 3c19a5d751cf19e093b7447297731124d9cc987d3f91a9d1872c3b1c1b15639a ' in db . hash_db , db . hash_db
2016-12-13 08:54:33 +01:00
assert ' e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ' not in db . hash_db , db . hash_db
2016-12-15 10:24:04 +01:00
def test_verify_ok ( ) :
temporary_folder , folder = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2016-12-15 10:24:04 +01:00
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
runner . invoke ( elodie . _generate_db , [ ' --path ' , folder ] )
result = runner . invoke ( elodie . _verify , [ ' --path ' , folder ] )
2016-12-15 10:24:04 +01:00
shutil . rmtree ( folder )
assert ' Success 1 ' in result . output , result . output
assert ' Error 0 ' in result . output , result . output
def test_verify_error ( ) :
temporary_folder , folder = helper . create_working_folder ( )
2021-06-20 08:35:28 +02:00
origin = ' %s /photo.png ' % folder
shutil . copyfile ( helper . get_file ( ' photo.png ' ) , origin )
2016-12-15 10:24:04 +01:00
runner = CliRunner ( )
2021-06-27 07:00:04 +02:00
runner . invoke ( elodie . _generate_db , [ ' --path ' , folder ] )
2016-12-15 10:24:04 +01:00
with open ( origin , ' w ' ) as f :
f . write ( ' changed text ' )
2021-06-27 07:00:04 +02:00
result = runner . invoke ( elodie . _verify , [ ' --path ' , folder ] )
2016-12-15 10:24:04 +01:00
shutil . rmtree ( folder )
assert origin in result . output , result . output
assert ' Error 1 ' in result . output , result . output
2017-05-12 08:43:16 +02:00
2021-06-27 07:00:04 +02:00
@unittest.skip ( ' depreciated ' )
2021-04-16 20:02:14 +02:00
@mock.patch ( ' elodie.constants.CONFIG_FILE ' , ' %s /config.ini-cli-batch-plugin-googlephotos ' % gettempdir ( ) )
2019-07-12 09:40:38 +02:00
def test_cli_batch_plugin_googlephotos ( ) :
auth_file = helper . get_file ( ' plugins/googlephotos/auth_file.json ' )
secrets_file = helper . get_file ( ' plugins/googlephotos/secrets_file.json ' )
config_string = """
[ Plugins ]
plugins = GooglePhotos
[ PluginGooglePhotos ]
auth_file = { }
secrets_file = { }
"""
config_string_fmt = config_string . format (
auth_file ,
secrets_file
)
with open ( ' %s /config.ini-cli-batch-plugin-googlephotos ' % gettempdir ( ) , ' w ' ) as f :
f . write ( config_string_fmt )
if hasattr ( load_config , ' config ' ) :
del load_config . config
final_file_path_1 = helper . get_file ( ' plain.jpg ' )
final_file_path_2 = helper . get_file ( ' no-exif.jpg ' )
sample_metadata_1 = Photo ( final_file_path_1 ) . get_metadata ( )
sample_metadata_2 = Photo ( final_file_path_2 ) . get_metadata ( )
gp = GooglePhotos ( )
gp . after ( ' ' , ' ' , final_file_path_1 , sample_metadata_1 )
gp . after ( ' ' , ' ' , final_file_path_2 , sample_metadata_1 )
2019-10-28 04:19:51 +01:00
runner = CliRunner ( )
result = runner . invoke ( elodie . _batch )
2019-07-12 09:40:38 +02:00
if hasattr ( load_config , ' config ' ) :
del load_config . config
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
2019-07-11 10:51:34 +02:00
2021-06-27 07:00:04 +02:00
@unittest.skip ( ' to fix ' )
2017-05-12 08:43:16 +02:00
def test_cli_debug_import ( ) :
2021-06-27 07:00:04 +02:00
import ipdb ; ipdb . set_trace ( )
2017-05-12 08:43:16 +02:00
runner = CliRunner ( )
# import
result = runner . invoke ( elodie . _import , [ ' --destination ' , ' /does/not/exist ' , ' /does/not/exist ' ] )
assert " Could not find /does/not/exist \n " not in result . output , result . output
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
2021-06-27 07:00:04 +02:00
@unittest.skip ( ' to fix ' )
2017-05-12 08:43:16 +02:00
def test_cli_debug_update ( ) :
runner = CliRunner ( )
# update
result = runner . invoke ( elodie . _update , [ ' --location ' , ' foobar ' , ' /does/not/exist ' ] )
assert " Could not find /does/not/exist \n " not in result . output , result . output
result = runner . invoke ( elodie . _update , [ ' --location ' , ' foobar ' , ' --debug ' , ' /does/not/exist ' ] )
assert " Could not find /does/not/exist \n " in result . output , result . output