Exemplo n.º 1
0
def test_set_config_read_ini_file():
    config = Destination_path_pattern()
    config_ini = os.path.join(os.getcwd(), 'elodie', 'tests', 'files',
                              'config_extended_1.ini')
    config.read_config_file(config_ini)
    raw_full_path = config.get_raw_full_path()
    assert raw_full_path == '%Y/%B', raw_full_path
Exemplo n.º 2
0
    def get_folder_path(self, metadata, path_parts=None):
        """Given a media's metadata this function returns the folder path as a string.

        :param metadata dict: Metadata dictionary.
        :optional param path_parts list of tuples: Pre-defined path definition (for unit test)
        :returns: str
        """

        # Stitch in the extended folder_path handler
        config = Destination_path_pattern()
        config_ini = os.path.join(os.getcwd(), 'elodie', 'tests', 'files',
                                  'config_extended_1.ini')
        config.read_config_file(config_file)
        raw_full_path = config.get_raw_full_path()
        if raw_full_path != '':
            fpconfig = Destination_actual_path(
                raw_full_path,
                '')  # Don't need the filepath as we'll fake the metadata
            fpconfig._set_metadata(metadata)
            full_path = fpconfig.get_full_path()
            return full_path
        # else extended folder_path handler is not specified in config.ini

        if not path_parts:
            path_parts = self.get_folder_path_definition()
        path = []
        for path_part in path_parts:
            # We support fallback values so that
            #  'album|city|"Unknown Location"
            #  %album|%city|"Unknown Location" results in
            #  My Album - when an album exists
            #  Sunnyvale - when no album exists but a city exists
            #  Unknown Location - when neither an album nor location exist
            for this_part in path_part:
                part, mask = this_part
                if part in ('date', 'day', 'month', 'year'):
                    path.append(time.strftime(mask, metadata['date_taken']))
                    break
                elif part in ('location', 'hamlet', 'village', 'town', 'city',
                              'state', 'country'):
                    place_name = geolocation.place_name(
                        metadata['latitude'], metadata['longitude'])

                    # TBD _x = self._parseFallbacks(metadata, mask)
                    location_parts = re.findall('(%[^%]+)', mask)
                    parsed_folder_name = self.parse_mask_for_location(
                        mask,
                        location_parts,
                        place_name,
                    )
                    path.append(parsed_folder_name)
                    break
                elif part in ('album', 'camera_make', 'camera_model'):
                    if metadata[part]:
                        path.append(metadata[part])
                        break
                elif part.startswith('"') and part.endswith('"'):
                    path.append(part[1:-1])

        return os.path.join(*path)
Exemplo n.º 3
0
def __do_test(config_str, metadata):
    config = Destination_path_pattern()
    config._set_config(config_str)
    raw_full_path = config.get_raw_full_path()

    fpconfig = Destination_actual_path(
        raw_full_path,
        '')  # Don't need the filepath as we'll fake the metadata
    fpconfig._set_metadata(metadata)
    full_path = fpconfig.get_full_path()
    return full_path
Exemplo n.º 4
0
def test_set_config_from_noFolder():
    config_string = """
[MapQuest]
key=your-api-key-goes-here

[Directory]
# Handled by original code, ignored by these tests
"""
    config = Destination_path_pattern()
    config._set_config(config_string)
    raw_full_path = config.get_raw_full_path()
    assert raw_full_path == '', raw_full_path
Exemplo n.º 5
0
def test_set_config_from_text():
    config = Destination_path_pattern()
    config._set_config(config_string1)
    raw_full_path = config.get_raw_full_path()
    assert raw_full_path == config_string1_full_path, raw_full_path

    config._set_config(config_string2)
    raw_full_path = config.get_raw_full_path()
    assert raw_full_path == config_string2_full_path, raw_full_path
Exemplo n.º 6
0
def test_get_full_path_fallback2():
    # RHS of fallback fails - there is no village
    config_str = """
[Folder]
month = %B
year = %Y
full_path = %country/%city/${year}/${month} | %village/%city/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK/Carlisle/2017/December', '"%s"' % full_path
Exemplo n.º 7
0
def test_get_full_path_minuses():
    config_str = """
[Folder]
month = %B
year = %Y
location = %country-%city
full_path = ${location}/${year}-${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK-Carlisle/2017-December', full_path
Exemplo n.º 8
0
def test_get_full_path_TEXT():
    config_str = """
[Folder]
month = %B
year = %Y
location = %country/%city
full_path = ${location}/%"TEXT"/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK/Carlisle/TEXT/2017/December', full_path
Exemplo n.º 9
0
def test_get_full_path_UNKNOWN_LOCATION():
    config_str = """
[Folder]
month = %B
year = %Y
location = %country/%village
full_path = ${location}/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK/UNKNOWN LOCATION/2017/December', full_path
Exemplo n.º 10
0
def test_get_full_path_fallback3():
    # RHS of fallback fails - there is no village
    # Using user-defined variables for locations
    config_str = """
[Folder]
month = %B
year = %Y
location1 = %country/%city
location2 = %village/%city
full_path = ${location1}/${year}/${month} | ${location2}/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK/Carlisle/2017/December', '"%s"' % full_path
Exemplo n.º 11
0
def test_get_full_path_fallback_noLocation():
    # GPS but no location component comes out as UNKNOWN LOCATION
    # Using user-defined variables for locations
    config_str = """
[Folder]
month = %B
year = %Y
location1 = %country/%hamlet
location2 = %village/%city
# If neither of the above work, fall back on just country
# If that's not available we will get UNKNOWN LOCATION
location3 = %village
full_path = ${location1}/${year}/${month} | ${location2}/${year}/${month} | ${location3}/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UNKNOWN LOCATION/2017/December', '"%s"' % full_path
Exemplo n.º 12
0
def test_get_full_path_fallback_noGPS():
    # No GPS so location component comes out as NO GPS
    # Using user-defined variables for locations
    config_str = """
[Folder]
month = %B
year = %Y
location1 = %country/%city
location2 = %village/%city
# If neither of the above work, fall back on just country
# If that's not available we will get NO GPS
location3 = %country
full_path = ${location1}/${year}/${month} | ${location2}/${year}/${month} | ${location3}/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata_no_GPS)
    assert full_path == 'NO GPS/2017/December', '"%s"' % full_path
Exemplo n.º 13
0
def test_get_full_path_fallback_toCountryOnly():
    # First two fallbacks fail - there is no village
    # Using user-defined variables for locations
    config_str = """
[Folder]
month = %B
year = %Y
location1 = %country/%village
location2 = %village/%city
# If neither of the above work, fall back on just country
# If that's not available we will get NO GPS
location3 = %country
full_path = ${location1}/${year}/${month} | ${location2}/${year}/${month} | ${location3}/${year}/${month}
"""
    config = Destination_path_pattern()
    full_path = __do_test(config_str, metadata)
    assert full_path == 'UK/2017/December', '"%s"' % full_path