def test_sync_password_as_environment_variable( 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_sleep.side_effect = [ None, Exception(), ] with patch.dict(os.environ, {ENV_ICLOUD_PASSWORD_KEY: data.VALID_PASSWORD}): with self.assertRaises(Exception): sync.sync() self.assertTrue( len([ e for e in captured[1] if "Error: 2FA is required. Please log in." in e ]) > 0)
def test_sync_different_schedule( self, mock_read_config, mock_service, mock_get_username, mock_get_password, mock_sleep, mock_stdout, mock_sync_photos, mock_sync_drive, ): mock_service = self.service if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] config = self.config.copy() config["drive"]["sync_interval"] = 1 config["photos"]["sync_interval"] = 2 mock_read_config.return_value = config mock_sync_drive.sync_drive.return_value = None mock_sync_photos.sync_photos.return_value = None mock_sleep.side_effect = [ None, None, None, None, None, None, None, Exception(), ] with self.assertRaises(Exception): sync.sync() self.assertEqual(mock_sync_drive.sync_drive.call_count, 6) self.assertEqual(mock_sync_photos.sync_photos.call_count, 3)
def test_sync_password_missing_in_keyring( self, mock_read_config, mock_service, mock_get_username, mock_get_password, mock_sleep, ): mock_service = self.service if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] config = self.config.copy() mock_read_config.return_value = config with self.assertLogs() as captured: mock_get_password.return_value = None mock_sleep.side_effect = [ None, Exception(), ] with self.assertRaises(Exception): sync.sync() self.assertTrue( len([ e for e in captured[1] if "Password is not stored in keyring. Please save the password in keyring." in e ]) > 0)
def test_sync_2fa_required( 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 if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] with self.assertLogs() as captured: mock_get_username.return_value = data.REQUIRES_2FA_USER mock_sleep.side_effect = [ None, Exception(), ] with self.assertRaises(Exception): sync.sync() self.assertTrue(len(captured.records) > 1) self.assertTrue( len([e for e in captured[1] if "2FA is required" in e]) > 0)
def test_sync_exception_thrown( self, mock_read_config, mock_service, mock_get_username, mock_get_password, mock_sleep, ): mock_service = self.service config = self.config.copy() config["drive"]["sync_interval"] = 1 config["drive"]["sync_interval"] = 1 mock_read_config.return_value = config mock_sleep.side_effect = Exception() config = self.config.copy() mock_read_config.return_value = config with self.assertRaises(Exception): sync.sync()
def test_sync( self, mock_read_config, mock_service, mock_get_username, mock_get_password, ): mock_service = self.service config = self.config.copy() mock_read_config.return_value = config if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] self.assertIsNone(sync.sync()) self.assertTrue(os.path.isdir("./session_data"))
def test_sync_empty(self, mock_read_config, mock_service, mock_get_username, mock_get_password): mock_service = self.service if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] # Nothing to sync config = self.config.copy() del config["photos"] del config["drive"] self.remove_temp() mock_read_config.return_value = config self.assertIsNone(sync.sync()) self.assertFalse(os.path.exists(self.root_dir))
def test_sync_photos_only( self, mock_read_config, mock_service, mock_get_username, mock_get_password, ): mock_service = self.service if ENV_ICLOUD_PASSWORD_KEY in os.environ: del os.environ[ENV_ICLOUD_PASSWORD_KEY] # Sync only photos config = self.config.copy() del config["drive"] self.remove_temp() mock_read_config.return_value = config self.assertIsNone(sync.sync()) dir_length = len(os.listdir(self.root_dir)) self.assertTrue(1 == dir_length) self.assertTrue( os.path.isdir( os.path.join(self.root_dir, config["photos"]["destination"])))
puts(colored.green("Successfully logged in")) elif 'init-session' in args: init_session() puts(colored.green("Successfully logged in")) validate_cookies() # recover previous session session = requests.session() with open(COOKIES_PATH, 'rb') as cookiesfile: session.cookies.update(pickle.load(cookiesfile)) validate_session(session) flags = args.flags if 'status' in args: summary(session, '--solved' in flags or '-s' in flags) elif 'sync' in args: sync_samples = '--sync-samples' in flags or '-ssa' in flags or '--sync-all' in flags or '-sa' in flags sync_statements = '--sync-statements' in flags or '-sst' in flags or '--sync-all' in flags or '-sa' in flags sync(session, sync_samples, sync_statements) elif 'standings' in args: standings(session) elif 'test' in args: test(args) elif 'style' in args: style(args) # menu = login(session) # print(menu)
__author__ = "Mandar Patil ([email protected])" from src import sync if __name__ == "__main__": sync.sync()