Added comments/likes, implements #214

This commit is contained in:
Rhet Turnbull
2020-10-25 22:12:02 -07:00
parent 4fe58bf2af
commit 23de6b5890
11 changed files with 305 additions and 10 deletions

71
tests/test_comments.py Normal file
View File

@@ -0,0 +1,71 @@
""" Test comments and likes """
import datetime
import pytest
import osxphotos
from osxphotos import CommentInfo, LikeInfo
PHOTOS_DB = "tests/Test-Cloud-10.15.6.photoslibrary"
COMMENT_UUID_DICT = {
"4AD7C8EF-2991-4519-9D3A-7F44A6F031BE": [
CommentInfo(
datetime=datetime.datetime(2020, 9, 18, 10, 28, 41, 552000),
user=None,
ismine=False,
text="Nice photo!",
),
CommentInfo(
datetime=datetime.datetime(2020, 9, 19, 22, 52, 20, 12014),
user=None,
ismine=True,
text="Wish I was back here!",
),
],
"CCBE0EB9-AE9F-4479-BFFD-107042C75227": [],
"4E4944A0-3E5C-4028-9600-A8709F2FA1DB": [
CommentInfo(
datetime=datetime.datetime(2020, 9, 19, 22, 54, 12, 947978),
user=None,
ismine=True,
text="Nice trophy",
)
],
}
LIKE_UUID_DICT = {
"4AD7C8EF-2991-4519-9D3A-7F44A6F031BE": [
LikeInfo(
datetime=datetime.datetime(2020, 9, 18, 10, 28, 43, 335000),
user=None,
ismine=False,
)
],
"CCBE0EB9-AE9F-4479-BFFD-107042C75227": [],
"65BADBD7-A50C-4956-96BA-1BB61155DA17": [
LikeInfo(
datetime=datetime.datetime(2020, 9, 18, 10, 28, 52, 570000),
user=None,
ismine=False,
)
],
}
@pytest.fixture(scope="module")
def photosdb():
return osxphotos.PhotosDB(dbfile=PHOTOS_DB)
def test_comments(photosdb):
for uuid in COMMENT_UUID_DICT:
photo = photosdb.get_photo(uuid)
assert photo.comments == COMMENT_UUID_DICT[uuid]
def test_likes(photosdb):
for uuid in LIKE_UUID_DICT:
photo = photosdb.get_photo(uuid)
assert photo.likes == LIKE_UUID_DICT[uuid]

View File

@@ -8,6 +8,8 @@ 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"
PHOTOS_DB_COMMENTS = "tests/Test-Cloud-10.15.6.photoslibrary"
UUID_DICT = {
"place_dc": "128FB4C6-0B16-4E7D-9108-FB2E90DA1546",
"1_1_2": "1EB2B765-0765-43BA-A90C-0D0580E6172C",
@@ -99,6 +101,15 @@ TEMPLATE_VALUES_DEU = {
"{place.address.country_code}": "US",
}
COMMENT_UUID_DICT = {
"4AD7C8EF-2991-4519-9D3A-7F44A6F031BE": [
"None: Nice photo!",
"None: Wish I was back here!",
],
"CCBE0EB9-AE9F-4479-BFFD-107042C75227": ["_"],
"4E4944A0-3E5C-4028-9600-A8709F2FA1DB": ["None: Nice trophy"],
}
def test_lookup():
""" Test that a lookup is returned for every possible value """
@@ -502,3 +513,13 @@ def test_subst_expand_inplace_3():
template, expand_inplace=True, inplace_sep="; "
)
assert sorted(rendered) == sorted(expected)
def test_comment():
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB_COMMENTS)
for uuid in COMMENT_UUID_DICT:
photo = photosdb.get_photo(uuid)
comments = photo.render_template("{comment}")
assert comments[0] == COMMENT_UUID_DICT[uuid]