Skip to content

Commit

Permalink
Test case for fix of auto-delete date mismatch icloud-photos-download…
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenmartin committed Jun 7, 2023
1 parent 752b79d commit cc65672
Show file tree
Hide file tree
Showing 2 changed files with 18,131 additions and 5 deletions.
97 changes: 92 additions & 5 deletions tests/test_autodelete_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,93 @@ class AutodeletePhotosTestCase(TestCase):
def inject_fixtures(self, caplog):
self._caplog = caplog

def test_download_autodelete_photos(self):
base_dir = os.path.normpath(f"tests/fixtures/Photos/{inspect.stack()[0][3]}")
if os.path.exists(base_dir):
shutil.rmtree(base_dir)
os.makedirs(base_dir)

files = [
"2023/06/06/IMG_3589.JPG"
]

with vcr.use_cassette("tests/vcr_cassettes/download_autodelete_photos.yml"):
# Pass fixed client ID via environment variable
runner = CliRunner(env={
"CLIENT_ID": "DE309E26-942E-11E8-92F5-14109FE0B321"
})
result = runner.invoke(
main,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"1",
"--delete-after-download",
"-d",
base_dir,
],
)

self.assertIn("DEBUG Looking up all photos and videos from album All Photos...", self._caplog.text)
self.assertIn(
f"INFO Downloading the first original photo or video to {base_dir} ...",
self._caplog.text,
)
self.assertIn(
f"INFO Downloading {os.path.join(base_dir, os.path.normpath('2023/06/06/IMG_3589.JPG'))}",
self._caplog.text,
)
self.assertIn(
f"INFO Deleting IMG_3589.JPG",
self._caplog.text,
)
self.assertIn(
"INFO All photos have been downloaded!", self._caplog.text
)

#check files
for file_name in files:
assert os.path.exists(os.path.join(base_dir, file_name)), f"{file_name} expected, but missing"

result = runner.invoke(
main,
[
"--username",
"[email protected]",
"--password",
"password1",
"--recent",
"0",
"--auto-delete",
"-d",
base_dir,
],
)

self.assertIn("DEBUG Looking up all photos and videos from album All Photos...", self._caplog.text)
self.assertIn(
f"INFO Downloading 0 original photos and videos to {base_dir} ...",
self._caplog.text,
)
self.assertIn(
f"INFO All photos have been downloaded!", self._caplog.text
)
self.assertIn(
f"INFO Deleting any files found in 'Recently Deleted'...",
self._caplog.text,
)

self.assertIn(
f"INFO Deleting {os.path.join(base_dir, os.path.normpath('2023/06/06/IMG_3589.JPG'))}",
self._caplog.text,
)

for file_name in files:
assert not os.path.exists(os.path.join(base_dir, file_name)), f"{file_name} not expected, but present"

def test_autodelete_photos(self):
base_dir = os.path.normpath(f"tests/fixtures/Photos/{inspect.stack()[0][3]}")
if os.path.exists(base_dir):
Expand All @@ -29,13 +116,13 @@ def test_autodelete_photos(self):
files_to_delete = [
"2018/07/30/IMG_7406.MOV",
"2018/07/26/IMG_7383.PNG",
"2018/07/12/IMG_7190.JPG",
"2018/07/12/IMG_7190-medium.JPG"
"2018/07/11/IMG_7190.JPG",
"2018/07/11/IMG_7190-medium.JPG"
]

os.makedirs(os.path.join(base_dir, "2018/07/30/"))
os.makedirs(os.path.join(base_dir, "2018/07/26/"))
os.makedirs(os.path.join(base_dir, "2018/07/12/"))
os.makedirs(os.path.join(base_dir, "2018/07/11/"))

# create some empty files
for file_name in files_to_create + files_to_delete:
Expand Down Expand Up @@ -88,11 +175,11 @@ def test_autodelete_photos(self):
self._caplog.text,
)
self.assertIn(
f"INFO Deleting {os.path.join(base_dir, os.path.normpath('2018/07/12/IMG_7190.JPG'))}",
f"INFO Deleting {os.path.join(base_dir, os.path.normpath('2018/07/11/IMG_7190.JPG'))}",
self._caplog.text,
)
self.assertIn(
f"INFO Deleting {os.path.join(base_dir, os.path.normpath('2018/07/12/IMG_7190-medium.JPG'))}",
f"INFO Deleting {os.path.join(base_dir, os.path.normpath('2018/07/11/IMG_7190-medium.JPG'))}",
self._caplog.text,
)

Expand Down
Loading

0 comments on commit cc65672

Please sign in to comment.