|
13 | 13 | import pytest |
14 | 14 | from click.testing import CliRunner |
15 | 15 | from piexif._exceptions import InvalidImageDataError |
16 | | -from requests import Response |
| 16 | +from requests import Response, Timeout |
17 | 17 | from requests.exceptions import ConnectionError |
18 | 18 | from vcr import VCR |
19 | 19 |
|
@@ -543,11 +543,11 @@ def mocked_authenticate(self: PyiCloudService) -> None: |
543 | 543 |
|
544 | 544 | assert result.exit_code == 1 |
545 | 545 |
|
546 | | - def test_handle_connection_error_name_id7(self) -> None: |
| 546 | + def test_timeout_error(self) -> None: |
547 | 547 | base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3]) |
548 | 548 |
|
549 | 549 | def mock_raise_response_error(_arg: Any) -> NoReturn: |
550 | | - raise ConnectionError("Connection Error") |
| 550 | + raise Timeout("Connection Error") |
551 | 551 |
|
552 | 552 | with mock.patch.object(PhotoAsset, "download") as pa_download: |
553 | 553 | pa_download.side_effect = mock_raise_response_error |
@@ -599,6 +599,63 @@ def mocked_authenticate(self: PyiCloudService) -> None: |
599 | 599 | ) |
600 | 600 | assert result.exit_code == 0 |
601 | 601 |
|
| 602 | + def test_handle_connection_error_name_id7(self) -> None: |
| 603 | + base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3]) |
| 604 | + |
| 605 | + def mock_raise_response_error(_arg: Any) -> NoReturn: |
| 606 | + raise ConnectionError("Connection Error") |
| 607 | + |
| 608 | + with mock.patch.object(PhotoAsset, "download") as pa_download: |
| 609 | + pa_download.side_effect = mock_raise_response_error |
| 610 | + |
| 611 | + # Let the initial authenticate() call succeed, |
| 612 | + # but do nothing on the second try. |
| 613 | + orig_authenticate = PyiCloudService.authenticate |
| 614 | + |
| 615 | + def mocked_authenticate(self: PyiCloudService) -> None: |
| 616 | + if not hasattr(self, "already_authenticated"): |
| 617 | + orig_authenticate(self) |
| 618 | + setattr(self, "already_authenticated", True) # noqa: B010 |
| 619 | + |
| 620 | + with mock.patch("icloudpd.constants.WAIT_SECONDS", 0): # noqa: SIM117 |
| 621 | + with mock.patch.object(PyiCloudService, "authenticate", new=mocked_authenticate): |
| 622 | + _, result = run_icloudpd_test( |
| 623 | + self.assertEqual, |
| 624 | + self.root_path, |
| 625 | + base_dir, |
| 626 | + "listing_photos.yml", |
| 627 | + [], |
| 628 | + [], |
| 629 | + [ |
| 630 | + "--username", |
| 631 | + "jdoe@gmail.com", |
| 632 | + "--password", |
| 633 | + "password1", |
| 634 | + "--recent", |
| 635 | + "1", |
| 636 | + "--skip-videos", |
| 637 | + "--skip-live-photos", |
| 638 | + "--no-progress-bar", |
| 639 | + "--file-match-policy", |
| 640 | + "name-id7", |
| 641 | + ], |
| 642 | + ) |
| 643 | + |
| 644 | + # Error msg should be repeated 5 times |
| 645 | + assert ( |
| 646 | + self._caplog.text.count( |
| 647 | + "Error downloading IMG_7409_QVk2Yyt.JPG, retrying after 0 seconds..." |
| 648 | + ) |
| 649 | + == 5 |
| 650 | + ) |
| 651 | + |
| 652 | + self.assertIn( |
| 653 | + "ERROR Could not download IMG_7409_QVk2Yyt.JPG. Please try again later.", |
| 654 | + self._caplog.text, |
| 655 | + ) |
| 656 | + assert result.exit_code == 0 |
| 657 | + |
| 658 | + |
602 | 659 | def test_handle_albums_error_name_id7(self) -> None: |
603 | 660 | base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3]) |
604 | 661 |
|
|
0 commit comments