Example #1
0
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()

    reset_hash_db()
    status = elodie.update_time(photo, origin, "2000-01-01 12:00:00")
    restore_hash_db()

    photo_processed = Photo(origin)
    metadata_processed = photo_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    assert metadata["date_taken"] != metadata_processed["date_taken"]
    assert metadata_processed["date_taken"] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed[
        "date_taken"
    ]
Example #2
0
def test_get_coordinates_without_exif():
    photo = Photo(helper.get_file('no-exif.jpg'))
    latitude = photo.get_coordinate('latitude')
    longitude = photo.get_coordinate('longitude')

    assert latitude is None, latitude
    assert longitude is None, longitude
Example #3
0
def test_set_utime_without_exif_date():
    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

    origin = os.path.join(folder,'photo.jpg')
    shutil.copyfile(helper.get_file('no-exif.jpg'), origin)

    media_initial = Photo(origin)
    metadata_initial = media_initial.get_metadata()

    initial_stat = os.stat(origin)
    initial_time = int(min(initial_stat.st_mtime, initial_stat.st_ctime))
    initial_checksum = helper.checksum(origin)

    assert initial_time == time.mktime(metadata_initial['date_taken'])

    filesystem.set_utime(media_initial)
    final_stat = os.stat(origin)
    final_checksum = helper.checksum(origin)

    media_final = Photo(origin)
    metadata_final = media_final.get_metadata()

    shutil.rmtree(folder)

    assert initial_time == final_stat.st_mtime
    assert final_stat.st_mtime == time.mktime(metadata_final['date_taken']), (final_stat.st_mtime, time.mktime(metadata_final['date_taken']))
    assert initial_checksum == final_checksum
Example #4
0
def _test_photo_type_set(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
    assert helper.isclose(metadata['latitude'], 11.1111111111), '{} lat {}'.format(type, metadata['latitude'])
    assert helper.isclose(metadata['longitude'], 99.9999999999), '{} lon {}'.format(type, metadata['latitude'])
Example #5
0
def _test_photo_type_get(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

        # downloading for each test is costly so we save it in the working directory
        file_path_save_as = helper.get_file_path(photo_name)
        if os.path.isfile(photo_file):
            shutil.copyfile(photo_file, file_path_save_as)

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(date), '{} date {}'.format(type, metadata['date_taken'])
Example #6
0
def test_set_location():
    raise SkipTest('gh-31, precision is lost in conversion from decimal to dms')
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    # Verify that original photo has no location information
    assert origin_metadata['latitude'] is None, origin_metadata['latitude']
    assert origin_metadata['longitude'] is None, origin_metadata['longitude']

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    # @TODO: understand why the decimal to degree conversion loses accuracy
    assert metadata['latitude'] == 11.1111111111, metadata['latitude']
    assert metadata['longitude'] == 99.9999999999, metadata['longitude']
Example #7
0
def test_get_date_taken_without_exif():
    source = helper.get_file('no-exif.jpg')
    photo = Photo(source)
    date_taken = photo.get_date_taken()

    date_taken_from_file = time.gmtime(min(os.path.getmtime(source), os.path.getctime(source)))

    assert date_taken == date_taken_from_file, date_taken
Example #8
0
def test_get_date_taken_without_exif():
    source = helper.get_file('no-exif.jpg')
    photo = Photo(source)
    date_taken = photo.get_date_taken()

    date_taken_from_file = time.gmtime(
        min(os.path.getmtime(source), os.path.getctime(source)))

    assert date_taken == date_taken_from_file, date_taken
Example #9
0
def test_get_folder_path_definition_multi_level_location_decode_known_city():
    destination_folder = DestinationFolder()
    media = Photo(helper.get_file('with-location.jpg'))
    _metadata = media.get_metadata()
    _metadata['latitude'] = 54.9286804166667
    _metadata['longitude'] = -2.94800427777778  # see mock_location_db_json_txt
    # use multi_level_location_expected, no need to recalculate
    path = destination_folder.get_folder_path(
        _metadata, path_parts=multi_level_location_definition_CCCV)

    assert path == os.path.join('UK', 'Carlisle', '2015', 'December'), path
Example #10
0
def test_get_folder_path_with_original_default_unknown_location():
    with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
        f.write('')
    if hasattr(load_config, 'config'):
        del load_config.config
    filesystem = FileSystem()
    media = Photo(helper.get_file('plain.jpg'))
    path = filesystem.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('2015-12-Dec','Unknown Location'), path
Example #11
0
def test_get_folder_path_with_int_in_source_path():
    # gh-239
    destination_folder = DestinationFolder()
    temporary_folder, folder = helper.create_working_folder('int')

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

    media = Photo(origin)
    path = destination_folder.get_folder_path(media.get_metadata())

    assert path == os.path.join('2015-12-Dec', 'Unknown Location'), path
Example #12
0
def test_get_folder_path_definition_multi_level_location_decode_known_county():
    destination_folder = DestinationFolder()
    media = Photo(helper.get_file('with-location.jpg'))
    _metadata = media.get_metadata()
    _metadata['latitude'] = 55.4874000277778
    _metadata['longitude'] = -3.290884
    # use multi_level_location_expected, no need to recalculate
    path = destination_folder.get_folder_path(
        _metadata, path_parts=multi_level_location_definition_CCCV)

    assert path == os.path.join('UK', 'Scottish Borders', '2015',
                                'December'), path
Example #13
0
def test_get_folder_path_definition_multi_level_location_decode_known_village(
):
    destination_folder = DestinationFolder()
    media = Photo(helper.get_file('with-location.jpg'))
    _metadata = media.get_metadata()
    _metadata['latitude'] = 55.92352675
    _metadata['longitude'] = -5.15257691666667  # see mock_location_db_json_txt
    # use multi_level_location_expected, no need to recalculate
    path = destination_folder.get_folder_path(
        _metadata, path_parts=multi_level_location_definition_CCCV)

    assert path == os.path.join('UK', 'Colintraive', '2015', 'December'), path
Example #14
0
def test_photo_extensions():
    photo = Photo()
    extensions = photo.extensions

    assert 'jpg' in extensions
    assert 'jpeg' in extensions
    assert 'nef' in extensions
    assert 'dng' in extensions
    assert 'gif' in extensions

    valid_extensions = Photo.get_valid_extensions()

    assert extensions == valid_extensions, valid_extensions
Example #15
0
def test_process_twice_more_than_two_levels_of_directories():
    with open('%s/config.ini-multiple-directories' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
year=%Y
month=%m
day=%d
full_path=%year/%month/%day
        """)

    if hasattr(load_config, 'config'):
        del load_config.config

    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

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

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

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

    if hasattr(load_config, 'config'):
        del load_config.config

    media_second = Photo(destination)
    media_second.set_title('foo')
    destination_second = filesystem.process_file(destination,
                                                 temporary_folder,
                                                 media_second,
                                                 allowDuplicate=True)

    if hasattr(load_config, 'config'):
        del load_config.config

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

    shutil.rmtree(folder)
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
Example #16
0
def test_set_utime_without_exif_date():
    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

    origin = os.path.join(folder,'photo.jpg')
    shutil.copyfile(helper.get_file('no-exif.jpg'), origin)

    media_initial = Photo(origin)
    metadata_initial = media_initial.get_metadata()

    initial_stat = os.stat(origin)
    initial_time = int(min(initial_stat.st_mtime, initial_stat.st_ctime))
    initial_checksum = helper.checksum(origin)

    assert initial_time == time.mktime(metadata_initial['date_taken'])

    filesystem.set_utime_from_metadata(media_initial.get_metadata(), media_initial.get_file_path())
    final_stat = os.stat(origin)
    final_checksum = helper.checksum(origin)

    media_final = Photo(origin)
    metadata_final = media_final.get_metadata()

    shutil.rmtree(folder)

    assert initial_time == final_stat.st_mtime
    assert final_stat.st_mtime == time.mktime(metadata_final['date_taken']), (final_stat.st_mtime, time.mktime(metadata_final['date_taken']))
    assert initial_checksum == final_checksum
Example #17
0
def test_get_folder_path_with_camera_make_and_model_fallback():
    with open('%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
full_path=%camera_make|"nomake"/%camera_model|"nomodel"
        """)
    if hasattr(load_config, 'config'):
        del load_config.config
    filesystem = FileSystem()
    media = Photo(helper.get_file('no-exif.jpg'))
    path = filesystem.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('nomake', 'nomodel'), path
Example #18
0
def test_get_folder_path_with_camera_make_and_model():
    with open('%s/config.ini-original-with-camera-make-and-model' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
full_path=%camera_make/%camera_model
        """)
    if hasattr(load_config, 'config'):
        del load_config.config
    filesystem = FileSystem()
    media = Photo(helper.get_file('plain.jpg'))
    path = filesystem.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path
Example #19
0
def test_process_file_with_album_and_title_and_location():
    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

    origin = os.path.join(folder, 'photo.jpg')
    shutil.copyfile(helper.get_file('with-album-and-title-and-location.jpg'),
                    origin)

    media = Photo(origin)
    destination = filesystem.process_file(origin,
                                          temporary_folder,
                                          media,
                                          allowDuplicate=True)

    origin_checksum = helper.checksum(origin)
    destination_checksum = helper.checksum(destination)

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

    assert origin_checksum is not None, origin_checksum
    assert origin_checksum == destination_checksum, destination_checksum
    assert helper.path_tz_fix(
        os.path.join('2015-12-Dec', 'Test Album',
                     '2015-12-05_00-59-26-photo-some-title.jpg')
    ) in destination, destination
Example #20
0
def test_get_file_name_with_title():
    filesystem = FileSystem()
    media = Photo(helper.get_file('with-title.jpg'))
    file_name = filesystem.get_file_name(media)

    assert file_name == helper.path_tz_fix(
        '2015-12-05_00-59-26-with-title-some-title.jpg'), file_name
Example #21
0
def test_get_file_name_plain():
    filesystem = FileSystem()
    media = Photo(helper.get_file('plain.jpg'))
    file_name = filesystem.get_file_name(media)

    assert file_name == helper.path_tz_fix(
        '2015-12-05_00-59-26-plain.jpg'), file_name
Example #22
0
def test_process_file_validate_original_checksum():
    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

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

    origin_checksum_preprocess = helper.checksum(origin)
    media = Photo(origin)
    destination = filesystem.process_file(origin,
                                          temporary_folder,
                                          media,
                                          allowDuplicate=True)

    origin_checksum = helper.checksum(origin)
    destination_checksum = helper.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
    assert destination_checksum is not None, destination_checksum
    assert origin_checksum_preprocess == origin_checksum, (
        origin_checksum_preprocess, origin_checksum)
Example #23
0
def test_process_file_fallback_folder():
    with open('%s/config.ini-fallback-folder' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
date=%Y-%m
full_path=%date/%album|"fallback"
        """)

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

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

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

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

    shutil.rmtree(folder)
    shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
Example #24
0
def test_process_file_with_plugin_runtime_error():
    with open('%s/config.ini-plugin-runtime-error' % gettempdir(), 'w') as f:
        f.write("""
[Plugins]
plugins=RuntimeError
        """)
    if hasattr(load_config, 'config'):
        del load_config.config

    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

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

    media = Photo(origin)
    destination = filesystem.process_file(origin,
                                          temporary_folder,
                                          media,
                                          allowDuplicate=True)

    if hasattr(load_config, 'config'):
        del load_config.config

    assert '2015-12-Dec/Unknown Location/2015-12-05_00-59-26-plain.jpg' in destination, destination
Example #25
0
def test_process_file_with_title():
    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('with-title.jpg'), origin)

    origin_checksum_preprocess = helper.checksum(origin)
    media = Photo(origin)
    destination = filesystem.process_file(origin,
                                          temporary_folder,
                                          media,
                                          allowDuplicate=True)

    origin_checksum = helper.checksum(origin)
    destination_checksum = helper.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
    assert destination_checksum is not None
    assert origin_checksum_preprocess == origin_checksum
    assert helper.path_tz_fix(
        os.path.join('2015-12-Dec', 'Unknown Location',
                     '2015-12-05_00-59-26-photo-some-title.jpg')
    ) in destination, destination
Example #26
0
def test_process_file_with_plugin_throw_error():
    with open('%s/config.ini-plugin-throw-error' % gettempdir(), 'w') as f:
        f.write("""
[Plugins]
plugins=ThrowError
        """)

    if hasattr(load_config, 'config'):
        del load_config.config

    filesystem = FileSystem()
    temporary_folder, folder = helper.create_working_folder()

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

    media = Photo(origin)
    destination = filesystem.process_file(origin,
                                          temporary_folder,
                                          media,
                                          allowDuplicate=True)

    if hasattr(load_config, 'config'):
        del load_config.config

    assert destination is None, destination
Example #27
0
def test_get_file_name_with_original_name_title_exif():
    filesystem = FileSystem()
    media = Photo(helper.get_file('with-filename-and-title-in-exif.jpg'))
    file_name = filesystem.get_file_name(media)

    assert file_name == helper.path_tz_fix(
        '2015-12-05_00-59-26-foobar-foobar-title.jpg'), file_name
Example #28
0
def test_get_file_name_with_uppercase_and_spaces():
    filesystem = FileSystem()
    media = Photo(helper.get_file('Plain With Spaces And Uppercase 123.jpg'))
    file_name = filesystem.get_file_name(media)

    assert file_name == helper.path_tz_fix(
        '2015-12-05_00-59-26-plain-with-spaces-and-uppercase-123.jpg'
    ), file_name
Example #29
0
def test_get_folder_path_with_int_in_config_component():
    # gh-239
    with open('%s/config.ini-int-in-component-path' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
date=%Y
full_path=%date
        """)
    if hasattr(load_config, 'config'):
        del load_config.config
    destination_folder = DestinationFolder()
    media = Photo(helper.get_file('plain.jpg'))
    path = destination_folder.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('2015'), path
Example #30
0
def test_set_location():
    raise SkipTest(
        'gh-31, precision is lost in conversion from decimal to dms')
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    # Verify that original photo has no location information
    assert origin_metadata['latitude'] is None, origin_metadata['latitude']
    assert origin_metadata['longitude'] is None, origin_metadata['longitude']

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    # @TODO: understand why the decimal to degree conversion loses accuracy
    assert metadata['latitude'] == 11.1111111111, metadata['latitude']
    assert metadata['longitude'] == 99.9999999999, metadata['longitude']
Example #31
0
def test_set_location():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    # Verify that original photo has different location info that what we
    #   will be setting and checking
    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)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
Example #32
0
def test_set_metadata_on_rw2():
    raise SkipTest('gh-94 Writing to RW2 images is not supported')
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.rw2')
    origin = '%s/photo.rw2' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.rw2', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('rw2 file not downlaoded')

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2014, 11, 19, 23, 7, 44, 2, 323, 0)), metadata['date_taken']
    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
Example #33
0
def _test_photo_type_set(type, date):
    temporary_folder, folder = helper.create_working_folder()

    photo_name = 'photo.{}'.format(type)
    photo_file = helper.get_file(photo_name)
    origin = '{}/{}'.format(folder, photo_name)

    if not photo_file:
        photo_file = helper.download_file(photo_name, folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('{} file not downlaoded'.format(type))

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert(
        date), '{} date {}'.format(type, metadata['date_taken'])
    assert helper.isclose(metadata['latitude'],
                          11.1111111111), '{} lat {}'.format(
                              type, metadata['latitude'])
    assert helper.isclose(metadata['longitude'],
                          99.9999999999), '{} lon {}'.format(
                              type, metadata['latitude'])
Example #34
0
def test_set_metadata_on_arw():
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.arw')
    origin = '%s/photo.arw' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.arw', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('arw file not downlaoded')

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_location(11.1111111111, 99.9999999999)

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken']
    assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
    assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
Example #35
0
def test_set_metadata_basename():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)

    metadata = photo.get_metadata()

    assert metadata['base_name'] == 'photo', metadata['base_name']

    new_basename = 'Some Base Name'
    photo.set_metadata_basename(new_basename)

    new_metadata = photo.get_metadata()

    assert new_metadata['base_name'] == new_basename, new_metadata['base_name']
Example #36
0
def test_get_folder_path_with_with_only_one_level():
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
year=%Y
full_path=%year
        """)

    if hasattr(load_config, 'config'):
        del load_config.config

    destination_folder = DestinationFolder()
    media = Photo(helper.get_file('plain.jpg'))
    path = destination_folder.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('2015'), path
Example #37
0
def test_get_folder_path_with_fallback_folder():
    with open('%s/config.ini-fallback' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
year=%Y
month=%m
full_path=%year/%month/%album|%"No Album Fool"/%month
        """)
#full_path=%year/%album|"No Album"
    if hasattr(load_config, 'config'):
        del load_config.config
    filesystem = FileSystem()
    media = Photo(helper.get_file('plain.jpg'))
    path = filesystem.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == os.path.join('2015','12','No Album Fool','12'), path
Example #38
0
def test_set_metadata():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)

    metadata = photo.get_metadata()

    assert metadata['title'] == None, metadata['title']

    new_title = 'Some Title'
    photo.set_metadata(title = new_title)

    new_metadata = photo.get_metadata()

    assert new_metadata['title'] == new_title, new_metadata['title']
Example #39
0
def test_get_folder_path_with_combined_date_and_album():
    # gh-239
    with open('%s/config.ini-combined-date-and-album' % gettempdir(), 'w') as f:
        f.write("""
[Directory]
date=%Y-%m-%b
custom=%date %album
full_path=%custom
        """)
    if hasattr(load_config, 'config'):
        del load_config.config
    filesystem = FileSystem()
    media = Photo(helper.get_file('with-album.jpg'))
    path = filesystem.get_folder_path(media.get_metadata())
    if hasattr(load_config, 'config'):
        del load_config.config

    assert path == '2015-12-Dec Test Album', path
Example #40
0
def test_set_title():
    temporary_folder, folder = helper.create_working_folder()

    origin = "%s/photo.jpg" % folder
    shutil.copyfile(helper.get_file("plain.jpg"), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_title("my photo title")

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata["title"] == "my photo title", metadata["title"]
Example #41
0
def test_set_title():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_title('my photo title')

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['title'] == 'my photo title', metadata['title']
Example #42
0
def test_set_date_taken():
    temporary_folder, folder = helper.create_working_folder()

    origin = "%s/photo.jpg" % folder
    shutil.copyfile(helper.get_file("plain.jpg"), origin)

    photo = Photo(origin)
    status = photo.set_date_taken(datetime.datetime(2013, 9, 30, 7, 6, 5))

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    date_taken = metadata["date_taken"]

    shutil.rmtree(folder)

    assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata["date_taken"]
Example #43
0
def test_set_title_non_ascii():
    raise SkipTest("gh-27, non-ascii characters")
    temporary_folder, folder = helper.create_working_folder()

    origin = "%s/photo.jpg" % folder
    shutil.copyfile(helper.get_file("plain.jpg"), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    status = photo.set_title("形声字 / 形聲字")

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata["title"] == "形声字 / 形聲字", metadata["title"]
Example #44
0
def test_set_title_non_ascii():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    origin_metadata = photo.get_metadata()

    unicode_title = u'形声字 / 形聲字'

    status = photo.set_title(unicode_title)
    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata['title'] == unicode_title, metadata['title']
Example #45
0
def test_set_album():
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('plain.jpg'), origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    assert metadata['album'] is None, metadata['album']

    status = photo.set_album('Test Album')

    assert status == True, status

    photo_new = Photo(origin)
    metadata_new = photo_new.get_metadata()

    shutil.rmtree(folder)

    assert metadata_new['album'] == 'Test Album', metadata_new['album']
Example #46
0
def test_set_date_taken_with_missing_datetimeoriginal():
    # When datetimeoriginal (or other key) is missing we have to add it gh-74
    # https://github.com/jmathai/elodie/issues/74
    temporary_folder, folder = helper.create_working_folder()

    origin = '%s/photo.jpg' % folder
    shutil.copyfile(helper.get_file('no-exif.jpg'), origin)

    photo = Photo(origin)
    status = photo.set_date_taken(datetime.datetime(2013, 9, 30, 7, 6, 5))

    assert status == True, status

    photo_new = Photo(origin)
    metadata = photo_new.get_metadata()

    date_taken = metadata['date_taken']

    shutil.rmtree(folder)

    assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata['date_taken']
Example #47
0
def test_photo_extensions():
    photo = Photo()
    extensions = photo.extensions

    assert "jpg" in extensions
    assert "jpeg" in extensions
    assert "nef" in extensions
    assert "dng" in extensions
    assert "gif" in extensions

    valid_extensions = Photo.get_valid_extensions()

    assert extensions == valid_extensions, valid_extensions
Example #48
0
def test_get_metadata_from_arw():
    temporary_folder, folder = helper.create_working_folder()

    photo_file = helper.get_file('photo.arw')
    origin = '%s/photo.arw' % folder

    if not photo_file:
        photo_file = helper.download_file('photo.arw', folder)
        if not photo_file or not os.path.isfile(photo_file):
            raise SkipTest('arw file not downlaoded')

        # downloading for each test is costly so we save it in the working directory
        file_path_save_as = helper.get_file_path('photo.arw')
        if os.path.isfile(photo_file):
            shutil.copyfile(photo_file, file_path_save_as)

    shutil.copyfile(photo_file, origin)

    photo = Photo(origin)
    metadata = photo.get_metadata()

    shutil.rmtree(folder)

    assert metadata['date_taken'] == helper.time_convert((2007, 4, 8, 17, 41, 18, 6, 98, 0)), metadata['date_taken']
Example #49
0
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()

    reset_hash_db()
    status = elodie.update_location(photo, origin, "Sunnyvale, CA")
    restore_hash_db()

    photo_processed = Photo(origin)
    metadata_processed = photo_processed.get_metadata()

    shutil.rmtree(folder)
    shutil.rmtree(folder_destination)

    assert status == True, status
    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"]
Example #50
0
def test_is_valid():
    photo = Photo(helper.get_file('plain.jpg'))

    assert photo.is_valid()
Example #51
0
def test_get_date_taken():
    photo = Photo(helper.get_file('plain.jpg'))
    date_taken = photo.get_date_taken()

#    assert date_taken == (2015, 12, 5, 0, 59, 26, 5, 339, 0), date_taken
    assert date_taken == helper.time_convert((2015, 12, 5, 0, 59, 26, 5, 339, 0)), date_taken
Example #52
0
def test_get_coordinate_longitude_plus():
    photo = Photo(helper.get_file('with-location-inv.jpg'))
    coordinate = photo.get_coordinate('longitude')

    assert helper.isclose(coordinate,122.033383611), coordinate
Example #53
0
def test_get_coordinate_latitude_minus():
    photo = Photo(helper.get_file('with-location-inv.jpg'))
    coordinate = photo.get_coordinate('latitude')

    assert helper.isclose(coordinate,-37.3667027222), coordinate
Example #54
0
def test_get_coordinate_default():
    photo = Photo(helper.get_file('with-location.jpg'))
    coordinate = photo.get_coordinate()

    assert helper.isclose(coordinate,37.3667027222), coordinate
Example #55
0
def test_get_metadata_of_invalid_photo():
    photo = Photo(helper.get_file('invalid.jpg'))
    metadata = photo.get_metadata()

    assert metadata is None
Example #56
0
def test_is_not_valid():
    photo = Photo(helper.get_file('text.txt'))

    assert not photo.is_valid()