Skip to content

Commit

Permalink
Merge pull request #69 from mandarons/retry_login_interval
Browse files Browse the repository at this point in the history
added retry_login_interval delay when retrying missing password
  • Loading branch information
mandarons committed Feb 15, 2022
2 parents 785974f + e520809 commit 3302893
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def sync():
LOGGER.error(
"Password is not stored in keyring. Please save the password in keyring."
)
sleep_for = config_parser.get_retry_login_interval(config=config)
next_sync = (
datetime.datetime.now() + datetime.timedelta(seconds=sleep_for)
).strftime("%c")
LOGGER.info("Retrying login at %s ...", next_sync)
last_send = notify.send(config, last_send)
sleep(sleep_for)
continue

if "drive" not in config and "photos" in config:
sleep_for = photos_sync_interval
enable_sync_drive = False
Expand Down
15 changes: 13 additions & 2 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,32 @@ def test_sync_2fa_required(
self.assertTrue(len(captured.records) > 1)
self.assertTrue(len([e for e in captured[1] if "2FA is required" in e]) > 0)

@patch("src.sync.sleep")
@patch(target="keyring.get_password", return_value=data.VALID_PASSWORD)
@patch(
target="src.config_parser.get_username", return_value=data.AUTHENTICATED_USER
)
@patch("icloudpy.ICloudPyService")
@patch("src.sync.read_config")
def test_sync_password_missing_in_keyring(
self, mock_read_config, mock_service, mock_get_username, mock_get_password
self,
mock_read_config,
mock_service,
mock_get_username,
mock_get_password,
mock_sleep,
):
mock_service = self.service
config = self.config.copy()
mock_read_config.return_value = config
with self.assertLogs() as captured:
mock_get_password.return_value = None
self.assertIsNone(sync.sync())
mock_sleep.side_effect = [
None,
Exception(),
]
with self.assertRaises(Exception):
sync.sync()
self.assertTrue(
len(
[
Expand Down

0 comments on commit 3302893

Please sign in to comment.