Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add debugging for unknown itemtype #986

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/pyicloud_ipd/services/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,12 @@ def dimensions(self) -> Tuple[int, int]:
@property
def item_type(self) -> AssetItemType:
fields = self._master_record['fields']
# TODO add wrapper for debugging
if 'itemType' not in fields or 'value' not in fields['itemType']:
raise ValueError("Unknown ItemType")
# return 'unknown'
item_type = self._master_record['fields']['itemType']['value']
if 'itemType' not in fields:
raise ValueError(f"Cannot find itemType in {fields!r}")
item_type_field = fields['itemType']
if 'value' not in item_type_field:
raise ValueError(f"Cannot find value in itemType {item_type_field!r}")
item_type = item_type_field['value']
if item_type in self.ITEM_TYPES:
return self.ITEM_TYPES[item_type]
if self.filename.lower().endswith(('.heic', '.png', '.jpg', '.jpeg')):
Expand Down
32 changes: 31 additions & 1 deletion tests/test_download_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ def astimezone(self, _tz: (Optional[Any]) = None) -> NoReturn:
self.assertIn("INFO All photos have been downloaded", self._caplog.text)
assert result.exit_code == 0

def test_unknown_item_type(self) -> None:
def test_missing_item_type(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

with mock.patch("icloudpd.download.download_media") as dp_patched:
Expand Down Expand Up @@ -1030,6 +1030,36 @@ def test_unknown_item_type(self) -> None:

self.assertIsInstance(result.exception, ValueError)

def test_missing_item_type_value(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

with mock.patch("icloudpd.download.download_media") as dp_patched:
dp_patched.return_value = True

data_dir, result = run_icloudpd_test(
self.assertEqual,
self.root_path,
base_dir,
"listing_photos_missing_item_type_value.yml",
[],
[],
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"1",
"--no-progress-bar",
"--threads-num",
"1",
],
)

dp_patched.assert_not_called()

self.assertIsInstance(result.exception, ValueError)

def test_download_and_dedupe_existing_photos(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

Expand Down
32 changes: 31 additions & 1 deletion tests/test_download_photos_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def astimezone(self, _tz: (Optional[Any]) = None) -> NoReturn:
self.assertIn("INFO All photos have been downloaded", self._caplog.text)
assert result.exit_code == 0

def test_unknown_item_type_name_id7(self) -> None:
def test_missing_item_type_name_id7(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

with mock.patch("icloudpd.download.download_media") as dp_patched:
Expand Down Expand Up @@ -979,6 +979,36 @@ def test_unknown_item_type_name_id7(self) -> None:

self.assertIsInstance(result.exception, ValueError)

def test_missing_item_type_value_name_id7(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

with mock.patch("icloudpd.download.download_media") as dp_patched:
dp_patched.return_value = True

data_dir, result = run_icloudpd_test(
self.assertEqual,
self.root_path,
base_dir,
"listing_photos_missing_item_type_value.yml",
[],
[],
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--recent",
"1",
"--no-progress-bar",
"--file-match-policy",
"name-id7",
],
)

dp_patched.assert_not_called()

self.assertIsInstance(result.exception, ValueError)

def test_download_and_dedupe_existing_photos_name_id7(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])

Expand Down
Loading
Loading