feat: update iPhone photo inbox scripts with environment file support and refactor batch handling

This commit is contained in:
2026-05-15 08:43:19 -06:00
parent 456a4c3381
commit 8950cfcdf0
6 changed files with 288 additions and 391 deletions

View File

@@ -20,22 +20,30 @@ SPEC.loader.exec_module(receiver)
class ReceiverTests(unittest.TestCase):
def tearDown(self) -> None:
for batch in getattr(self, "batches", []):
if batch.timer is not None:
batch.timer.cancel()
batch = getattr(self, "batch", None)
if batch is not None and batch.timer is not None:
batch.timer.cancel()
def test_mattermost_profile_defaults_to_files_clipboard(self) -> None:
profile = receiver.profile_defaults()["mattermost"]
self.assertEqual(profile.clipboard, receiver.CLIPBOARD_FILES)
def test_load_env_file_does_not_override_existing_environment(self) -> None:
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8") as env_file, \
patch.dict(receiver.os.environ, {"PHOTO_INBOX_TOKEN": "existing"}, clear=False):
env_file.write("PHOTO_INBOX_TOKEN=from-file\n")
env_file.write('PHOTO_INBOX_DEBOUNCE_SECONDS="5"\n')
env_file.flush()
def test_batch_add_accumulates_paths_by_profile(self) -> None:
manager = receiver.BatchManager(debounce_seconds=60)
profile = receiver.Profile("opencode", Path("/tmp"), receiver.CLIPBOARD_TERMINAL_PATH, notify=False)
receiver.load_env_file(Path(env_file.name))
count1, paths1 = manager.add(profile, Path("/tmp"), Path("/tmp/one.jpg"))
count2, paths2 = manager.add(profile, Path("/tmp"), Path("/tmp/two.jpg"))
self.assertEqual(receiver.os.environ["PHOTO_INBOX_TOKEN"], "existing")
self.assertEqual(receiver.os.environ["PHOTO_INBOX_DEBOUNCE_SECONDS"], "5")
self.batches = list(manager.batches.values())
def test_batch_add_accumulates_paths(self) -> None:
config = receiver.Config(Path("/tmp"), clipboard=True, notify=False, reveal=False)
manager = receiver.BatchManager(debounce_seconds=60, config=config)
count1, paths1 = manager.add(Path("/tmp/one.jpg"))
count2, paths2 = manager.add(Path("/tmp/two.jpg"))
self.batch = manager.batch
self.assertEqual(count1, 1)
self.assertEqual(paths1, [Path("/tmp/one.jpg")])
self.assertEqual(count2, 2)
@@ -57,13 +65,20 @@ class ReceiverTests(unittest.TestCase):
"/tmp/two.jpg",
])
def test_terminal_paths_clipboard_contains_all_paths(self) -> None:
paths = [Path("/tmp/one.jpg"), Path("/tmp/two with space.jpg")]
def test_build_config_uses_boolean_clipboard(self) -> None:
args = type("Args", (), {
"output_dir": Path("/tmp/photos"),
"clipboard": False,
"notify": True,
"reveal": False,
})()
with patch.object(receiver, "copy_text_to_clipboard", return_value=True) as copy_text:
self.assertTrue(receiver.apply_clipboard_mode(receiver.CLIPBOARD_TERMINAL_PATH, paths))
config = receiver.build_config(args)
copy_text.assert_called_once_with("/tmp/one.jpg\n'/tmp/two with space.jpg'")
self.assertEqual(config.output_dir, Path("/tmp/photos").resolve())
self.assertFalse(config.clipboard)
self.assertTrue(config.notify)
self.assertFalse(config.reveal)
if __name__ == "__main__":