Skip to content

Commit

Permalink
added test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarons committed Oct 5, 2023
1 parent 3902bb9 commit 0ebeb29
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def sync_photos(config, photos):
download_all = config_parser.get_photos_all_albums(config=config)
if download_all:
for album in photos.albums.keys():
if album in iter(filters["albums"]):
continue
sync_album(
album=photos.albums[album],
destination_path=os.path.join(destination_path, album),
Expand Down
58 changes: 58 additions & 0 deletions tests/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,64 @@ def request(self, method, url, **kwargs):
"query?remapEnums=True&getCurrentSyncToken=True"
][0]["response"]
)
if (
data.get("query").get("recordType")
== "CPLAssetAndMasterHiddenByAssetDate"
):
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
][5]["response"]
)
if (
data.get("query").get("recordType")
== "CPLAssetAndMasterDeletedByExpungedDate"
):
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
][5]["response"]
)
if (
data.get("query").get("recordType")
== "CPLBurstStackAssetAndMasterByAssetDate"
):
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
][5]["response"]
)

if data.get("query").get("recordType") in (
"CPLAssetAndMasterInSmartAlbumByAssetDate"
):
if "filterBy" in data["query"] and data.get("query").get(
"filterBy"
)[2]["fieldValue"]["value"] in (
"TIMELAPSE",
"LIVE",
"VIDEO",
"SLOMO",
"FAVORITE",
"SCREENSHOT",
"BURST",
"PANORAMA",
):
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
][5]["response"]
)
if (
"filterBy" in data["query"]
and data.get("query").get("filterBy")[2]["fieldValue"]["value"]
== "VIDEO"
):
return ResponseMock(
photos_data.DATA[
"query?remapEnums=True&getCurrentSyncToken=True"
][5]["response"]
)
if data.get("query").get("recordType") == "CPLAlbumByPositionLive":
if (
"filterBy" in data["query"]
Expand Down
28 changes: 28 additions & 0 deletions tests/test_sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ def test_sync_photos_original(
self.assertIsNone(
sync_photos.sync_photos(config=config, photos=mock_service.photos)
)
album_2_path = os.path.join(self.destination_path, "album 2")
album_1_1_path = os.path.join(album_2_path, "album-1-1")
album_1_path = os.path.join(self.destination_path, "album-1")
self.assertTrue(os.path.isdir(album_2_path))
self.assertTrue(os.path.isdir(album_1_path))
self.assertTrue(os.path.isdir(album_1_1_path))
self.assertTrue(len(os.listdir(album_2_path)) > 1)
self.assertTrue(len(os.listdir(album_1_path)) > 0)

@patch(target="keyring.get_password", return_value=data.VALID_PASSWORD)
@patch(
target="src.config_parser.get_username", return_value=data.AUTHENTICATED_USER
)
@patch("icloudpy.ICloudPyService")
@patch("src.read_config")
def test_sync_photos_all_albums(
self, mock_read_config, mock_service, mock_get_username, mock_get_password
):
"""Test for successful original photo size download."""
mock_service = self.service
config = self.config.copy()
config["photos"]["destination"] = self.destination_path
config["photos"]["all_albums"] = True
mock_read_config.return_value = config
# Sync original photos
self.assertIsNone(
sync_photos.sync_photos(config=config, photos=mock_service.photos)
)
album_0_path = os.path.join(
self.destination_path, config["photos"]["filters"]["albums"][0]
)
Expand Down

0 comments on commit 0ebeb29

Please sign in to comment.