Added {folder_album} to template and --folder to CLI
This commit is contained in:
@@ -2,10 +2,12 @@ import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
CLI_PHOTOS_DB = "tests/Test-10.15.1.photoslibrary"
|
||||
LIVE_PHOTOS_DB = "tests/Test-Cloud-10.15.1.photoslibrary/database/photos.db"
|
||||
LIVE_PHOTOS_DB = "tests/Test-Cloud-10.15.1.photoslibrary"
|
||||
RAW_PHOTOS_DB = "tests/Test-RAW-10.15.1.photoslibrary"
|
||||
PLACES_PHOTOS_DB = "tests/Test-Places-Catalina-10_15_1.photoslibrary"
|
||||
PLACES_PHOTOS_DB_13 = "tests/Test-Places-High-Sierra-10.13.6.photoslibrary"
|
||||
PHOTOS_DB_15_4 = "tests/Test-10.15.4.photoslibrary"
|
||||
PHOTOS_DB_14_6 = "tests/Test-10.14.6.photoslibrary"
|
||||
|
||||
CLI_OUTPUT_NO_SUBCOMMAND = [
|
||||
"Options:",
|
||||
@@ -658,3 +660,84 @@ def test_no_place_15():
|
||||
|
||||
assert len(json_got) == 1 # single element
|
||||
assert json_got[0]["uuid"] == "A9B73E13-A6F2-4915-8D67-7213B39BAE9F"
|
||||
|
||||
|
||||
def test_no_folder_1_15():
|
||||
# test --folder on 10.15
|
||||
import json
|
||||
import os
|
||||
import os.path
|
||||
import osxphotos
|
||||
from osxphotos.__main__ import query
|
||||
|
||||
runner = CliRunner()
|
||||
cwd = os.getcwd()
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PHOTOS_DB_15_4), "--json", "--folder", "Folder1"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
|
||||
assert len(json_got) == 2 # single element
|
||||
for item in json_got:
|
||||
assert item["uuid"] in [
|
||||
"3DD2C897-F19E-4CA6-8C22-B027D5A71907",
|
||||
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51",
|
||||
]
|
||||
assert item["albums"] == ["AlbumInFolder"]
|
||||
|
||||
|
||||
def test_no_folder_2_15():
|
||||
# test --folder with --uuid on 10.15
|
||||
import json
|
||||
import os
|
||||
import os.path
|
||||
import osxphotos
|
||||
from osxphotos.__main__ import query
|
||||
|
||||
runner = CliRunner()
|
||||
cwd = os.getcwd()
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[
|
||||
os.path.join(cwd, PHOTOS_DB_15_4),
|
||||
"--json",
|
||||
"--folder",
|
||||
"Folder1",
|
||||
"--uuid",
|
||||
"E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
|
||||
assert len(json_got) == 1 # single element
|
||||
for item in json_got:
|
||||
assert item["uuid"] == "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51"
|
||||
assert item["albums"] == ["AlbumInFolder"]
|
||||
|
||||
|
||||
def test_no_folder_1_14(caplog):
|
||||
# test --folder on 10.14
|
||||
import json
|
||||
import os
|
||||
import os.path
|
||||
import osxphotos
|
||||
from osxphotos.__main__ import query
|
||||
|
||||
runner = CliRunner()
|
||||
cwd = os.getcwd()
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PHOTOS_DB_14_6), "--json", "--folder", "Folder1"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
|
||||
assert len(json_got) == 0 # single element
|
||||
assert "not yet implemented" in caplog.text
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
""" Test template.py """
|
||||
import pytest
|
||||
|
||||
PHOTOS_DB_1 = "./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_2 = "./tests/Test-10.15.1.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_PLACES = (
|
||||
"./tests/Test-Places-Catalina-10_15_1.photoslibrary/database/photos.db"
|
||||
)
|
||||
PHOTOS_DB_15_1 = "./tests/Test-10.15.1.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_15_4 = "./tests/Test-10.15.4.photoslibrary/database/photos.db"
|
||||
PHOTOS_DB_14_6 = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
|
||||
|
||||
UUID_DICT = {
|
||||
"place_dc": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
|
||||
"1_1_2": "1EB2B765-0765-43BA-A90C-0D0580E6172C",
|
||||
"2_1_1": "D79B8D77-BFFC-460B-9312-034F2877D35B",
|
||||
"0_2_0": "6191423D-8DB8-4D4C-92BE-9BBBA308AAC4",
|
||||
"folder_album_1": "3DD2C897-F19E-4CA6-8C22-B027D5A71907",
|
||||
"folder_album_no_folder": "D79B8D77-BFFC-460B-9312-034F2877D35B",
|
||||
"mojave_no_folder": "15uNd7%8RguTEgNPKHfTWw",
|
||||
}
|
||||
|
||||
TEMPLATE_VALUES = {
|
||||
@@ -55,7 +63,7 @@ def test_lookup():
|
||||
TEMPLATE_SUBSTITUTIONS,
|
||||
)
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
for subst in TEMPLATE_SUBSTITUTIONS:
|
||||
@@ -71,7 +79,7 @@ def test_subst():
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US")
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
for template in TEMPLATE_VALUES:
|
||||
@@ -86,7 +94,7 @@ def test_subst_default_val():
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US")
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
template = "{place.name.area_of_interest,UNKNOWN}"
|
||||
@@ -101,7 +109,7 @@ def test_subst_default_val_2():
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US")
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
template = "{place.name.area_of_interest,}"
|
||||
@@ -116,7 +124,7 @@ def test_subst_unknown_val():
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US")
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
template = "{created.year}/{foo}"
|
||||
@@ -134,7 +142,7 @@ def test_subst_double_brace():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
template = "{created.year}/{{foo}}"
|
||||
@@ -150,7 +158,7 @@ def test_subst_unknown_val_with_default():
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US")
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_1)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_PLACES)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
template = "{created.year}/{foo,bar}"
|
||||
@@ -165,7 +173,7 @@ def test_subst_multi_1_1_2():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["1_1_2"]])[0]
|
||||
|
||||
template = "{created.year}/{album}/{keyword}/{person}"
|
||||
@@ -180,7 +188,7 @@ def test_subst_multi_2_1_1():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["2_1_1"]])[0]
|
||||
|
||||
@@ -200,7 +208,7 @@ def test_subst_multi_2_1_1_single():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["2_1_1"]])[0]
|
||||
|
||||
@@ -216,7 +224,7 @@ def test_subst_multi_0_2_0():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -232,7 +240,7 @@ def test_subst_multi_0_2_0_single():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -248,7 +256,7 @@ def test_subst_multi_0_2_0_default_val():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -264,7 +272,7 @@ def test_subst_multi_0_2_0_default_val_unknown_val():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -286,7 +294,7 @@ def test_subst_multi_0_2_0_default_val_unknown_val_2():
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_2)
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_1)
|
||||
# one album, one keyword, two persons
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["0_2_0"]])[0]
|
||||
|
||||
@@ -298,3 +306,52 @@ def test_subst_multi_0_2_0_default_val_unknown_val_2():
|
||||
rendered, unknown = render_filepath_template(template, photo)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == ["foo"]
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_1():
|
||||
""" Test substitutions for folder_album are correct """
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_4)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_1"]])[0]
|
||||
template = "{folder_album}"
|
||||
expected = ["Folder1/SubFolder2/AlbumInFolder"]
|
||||
rendered, unknown = render_filepath_template(template, photo)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_2():
|
||||
""" Test substitutions for folder_album are correct """
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_15_4)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["folder_album_no_folder"]])[0]
|
||||
template = "{folder_album}"
|
||||
expected = ["Pumpkin Farm", "Test Album"]
|
||||
rendered, unknown = render_filepath_template(template, photo)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
|
||||
|
||||
def test_subst_multi_folder_albums_3(caplog):
|
||||
""" Test substitutions for folder_album on < Photos 5 (not implemented) """
|
||||
import osxphotos
|
||||
from osxphotos.template import render_filepath_template
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_14_6)
|
||||
|
||||
# photo in an album in a folder
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["mojave_no_folder"]])[0]
|
||||
template = "{folder_album}"
|
||||
expected = ["Pumpkin Farm", "Test Album (1)"]
|
||||
rendered, unknown = render_filepath_template(template, photo)
|
||||
assert sorted(rendered) == sorted(expected)
|
||||
assert unknown == []
|
||||
assert "not yet implemented" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user