Skip to content

Commit

Permalink
According to README it download_all should ignore filtered albums.
Browse files Browse the repository at this point in the history
I missed it in preparing pull requests
  • Loading branch information
tymmej committed Oct 7, 2023
1 parent dc02947 commit 0814f01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ 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 filters["albums"] and album in iter(filters["albums"]):
continue
sync_album(
album=photos.albums[album],
destination_path=os.path.join(destination_path, album),
Expand Down
33 changes: 32 additions & 1 deletion tests/test_sync_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setUp(self) -> None:
def tearDown(self) -> None:
"""Remove temp directory."""
shutil.rmtree(tests.TEMP_DIR)
if os.path.exists(tests.PHOTOS_DIR):
shutil.rmtree(tests.PHOTOS_DIR)

@patch(target="keyring.get_password", return_value=data.VALID_PASSWORD)
@patch(
Expand Down Expand Up @@ -65,7 +67,7 @@ def test_sync_photos_original(
)
@patch("icloudpy.ICloudPyService")
@patch("src.read_config")
def test_sync_photos_all_albums(
def test_sync_photos_all_albums_filtered(
self, mock_read_config, mock_service, mock_get_username, mock_get_password
):
"""Test for successful original photo size download."""
Expand All @@ -84,6 +86,35 @@ def test_sync_photos_all_albums(
album_1_path = os.path.join(
self.destination_path, config["photos"]["filters"]["albums"][1]
)
self.assertFalse(os.path.isdir(album_0_path))
self.assertFalse(os.path.isdir(album_1_path))

@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_filtered(
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
album_0_path = os.path.join(
self.destination_path, config["photos"]["filters"]["albums"][0]
)
album_1_path = os.path.join(
self.destination_path, config["photos"]["filters"]["albums"][1]
)
config["photos"]["filters"]["albums"] = None
# Sync original photos
self.assertIsNone(
sync_photos.sync_photos(config=config, photos=mock_service.photos)
)
self.assertTrue(os.path.isdir(album_0_path))
self.assertTrue(os.path.isdir(album_1_path))
self.assertTrue(len(os.listdir(album_0_path)) > 1)
Expand Down

0 comments on commit 0814f01

Please sign in to comment.