"""Tests for multi-attachment URL collection.""" from __future__ import annotations from onedrive_planner import ( _attachment_tab_count, _merge_attachment_hrefs, _should_mark_task_in_progress, ) SAMPLE_A = ( "https://netorg393890.sharepoint.com/sites/ArborHills/Shared%20Documents/" "RICHARDSON%20ARBRHLS%205.26.26.pdf" ) SAMPLE_B = ( "https://netorg393890.sharepoint.com/sites/ArborHills/Shared%20Documents/" "RICHARDSON%20ARBRHLS%206.4.26.pdf" ) class TestAttachmentMulti: def test_merge_keeps_distinct_pdf_urls(self): merged = _merge_attachment_hrefs( [SAMPLE_A], [SAMPLE_B], [SAMPLE_A], ) assert len(merged) == 2 assert SAMPLE_A in merged assert SAMPLE_B in merged def test_merge_dedupes_same_filename(self): merged = _merge_attachment_hrefs([SAMPLE_A], [SAMPLE_A + "?download=1"]) assert len(merged) == 1 def test_mark_status_only_after_all_files(self, tmp_path): one = tmp_path / "a.pdf" two = tmp_path / "b.pdf" one.write_bytes(b"x") two.write_bytes(b"y") assert not _should_mark_task_in_progress([one], 2) assert _should_mark_task_in_progress([one, two], 2) assert not _should_mark_task_in_progress([], 2) assert _should_mark_task_in_progress([one], 0) def test_attachment_tab_count_parses_number(self): from unittest.mock import MagicMock tab = MagicMock() tab.is_displayed.return_value = True tab.text = "Attachments (2)" tab.get_attribute.return_value = "" driver = MagicMock() driver.find_elements.return_value = [tab] assert _attachment_tab_count(driver) == 2