Skip to content

Commit

Permalink
add debugging for unknown itemtype (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyNikiforov authored Nov 2, 2024
1 parent 4a2b3cc commit 9d74b24
Show file tree
Hide file tree
Showing 4 changed files with 44,818 additions and 7 deletions.
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",
"[email protected]",
"--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",
"[email protected]",
"--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

0 comments on commit 9d74b24

Please sign in to comment.