-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test case for fix of auto-delete date mismatch icloud-photos-download…
- Loading branch information
1 parent
752b79d
commit cc65672
Showing
2 changed files
with
18,131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
|
@@ -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: | ||
|
@@ -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, | ||
) | ||
|
||
|
Oops, something went wrong.