11from unittest import TestCase
2- from vcr import VCR
32import os
43import shutil
5- import click
6- from click .testing import CliRunner
74import json
85import mock
6+ from vcr import VCR
7+ from click .testing import CliRunner
98from icloudpd .base import main
109from tests .helpers .print_result_exception import print_result_exception
1110
1211vcr = VCR (decode_compressed_response = True )
1312
1413class ListingRecentPhotosTestCase (TestCase ):
14+
1515 def test_listing_recent_photos (self ):
1616 base_dir = os .path .normpath ("tests/fixtures/Photos" )
1717 if os .path .exists (base_dir ):
@@ -69,6 +69,45 @@ def test_listing_recent_photos(self):
6969 os .path .join (base_dir , os .path .normpath ("2018/07/30/IMG_7404.MOV" )), filenames [7 ]
7070 )
7171
72+ assert result .exit_code == 0
73+
74+ def test_listing_photos_does_not_create_folders (self ):
75+ base_dir = os .path .normpath ("tests/fixtures/Photos" )
76+ if os .path .exists (base_dir ):
77+ shutil .rmtree (base_dir )
78+ os .makedirs (base_dir )
79+
80+ # make sure the directory does not exist yet.
81+ # Should only be created after download, not after just --print-filenames
82+ self .assertFalse (os .path .exists (os .path .join (base_dir , os .path .normpath ("2018/07/31" ))))
83+
84+ # Note - This test uses the same cassette as test_download_photos.py
85+ with vcr .use_cassette ("tests/vcr_cassettes/listing_photos.yml" ):
86+ # Pass fixed client ID via environment variable
87+ os .environ ["CLIENT_ID" ] = "DE309E26-942E-11E8-92F5-14109FE0B321"
88+ runner = CliRunner ()
89+ result = runner .invoke (
90+ main ,
91+ [
92+ "--username" ,
93+ "jdoe@gmail.com" ,
94+ "--password" ,
95+ "password1" ,
96+ "--recent" ,
97+ "5" ,
98+ "--only-print-filenames" ,
99+ "--no-progress-bar" ,
100+ "--threads-num" ,
101+ 1 ,
102+ "-d" ,
103+ base_dir ,
104+ ],
105+ )
106+ print_result_exception (result )
107+ # make sure the directory still does not exist.
108+ # Should only be created after download, not after just --print-filenames
109+ self .assertFalse (
110+ os .path .exists (os .path .join (base_dir , os .path .normpath ("2018/07/31" ))))
72111
73112 assert result .exit_code == 0
74113
@@ -110,19 +149,24 @@ def test_listing_recent_photos_with_missing_filenameEnc(self):
110149
111150 # self.assertEqual(len(filenames), 5)
112151 self .assertEqual (
113- os .path .join (base_dir , os .path .normpath ("2018/07/31/AY6c_BsE0jja.JPG" )), filenames [0 ]
152+ os .path .join (base_dir , os .path .normpath ("2018/07/31/AY6c_BsE0jja.JPG" )),
153+ filenames [0 ]
114154 )
115155 self .assertEqual (
116- os .path .join (base_dir , os .path .normpath ("2018/07/31/AY6c_BsE0jja.MOV" )), filenames [1 ]
156+ os .path .join (base_dir , os .path .normpath ("2018/07/31/AY6c_BsE0jja.MOV" )),
157+ filenames [1 ]
117158 )
118159 self .assertEqual (
119- os .path .join (base_dir , os .path .normpath ("2018/07/30/IMG_7408.JPG" )), filenames [2 ]
160+ os .path .join (base_dir , os .path .normpath ("2018/07/30/IMG_7408.JPG" )),
161+ filenames [2 ]
120162 )
121163 self .assertEqual (
122- os .path .join (base_dir , os .path .normpath ("2018/07/30/IMG_7408.MOV" )), filenames [3 ]
164+ os .path .join (base_dir , os .path .normpath ("2018/07/30/IMG_7408.MOV" )),
165+ filenames [3 ]
123166 )
124167 self .assertEqual (
125- os .path .join (base_dir , os .path .normpath ("2018/07/30/AZ_wAGT9P6jh.JPG" )), filenames [4 ]
168+ os .path .join (base_dir , os .path .normpath ("2018/07/30/AZ_wAGT9P6jh.JPG" )),
169+ filenames [4 ]
126170 )
127171 assert result .exit_code == 0
128172
@@ -186,5 +230,4 @@ def test_listing_recent_photos_with_missing_downloadURL(self):
186230 self .assertEqual (
187231 first_arg ['asset_record' ]['fields' ]['assetDate' ]['value' ],
188232 1533021744816 )
189- assert result .exit_code == 0
190-
233+ assert result .exit_code == 0
0 commit comments