fix(contacts): warn on unsupported dict/list email/tel update inputs
Surface the text-merge update path's limitation rather than silently no-op: when contact_data['email'] or ['tel'] arrives as a dict/list on update, log a warning at the top of _merge_vcard_properties pointing callers at plain str or create_contact. Existing EMAIL/TEL lines are still preserved unchanged. Bring nc_contacts_update_contact docstring into parity with create — the update tool now documents the same keys plus the explicit single-string limitation for email/tel and the BDAY validation / URL first-only behaviours. Three new TestMergeVcardProperties cases pin the warning: dict email warns, list tel warns, plain str email is silent (no false positives). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
125ab40121
commit
c91be45374
@@ -368,3 +368,44 @@ class TestMergeVcardProperties:
|
||||
result = self._merge(existing, {"org": ["Acme", "Engineering"]})
|
||||
assert "ORG:Acme;Engineering" in result
|
||||
assert "[" not in result
|
||||
|
||||
def test_dict_email_on_no_existing_line_warns(self, caplog):
|
||||
"""No existing EMAIL + dict input is a known limitation of the text-merge
|
||||
path. Surface it as a warning so the silent no-op is at least observable.
|
||||
"""
|
||||
existing = "BEGIN:VCARD\nVERSION:3.0\nUID:merge-test\nFN:Alice\nEND:VCARD\n"
|
||||
with caplog.at_level("WARNING"):
|
||||
result = self._merge(
|
||||
existing, {"email": {"value": "alice@work.com", "type": ["WORK"]}}
|
||||
)
|
||||
# The dict input is not applied; no EMAIL line is added.
|
||||
assert "EMAIL" not in result
|
||||
# A warning specifically calls out the dict/list shape and recommends
|
||||
# plain str / create_contact as alternatives.
|
||||
assert any(
|
||||
"email" in r.message and "dict/list shape" in r.message
|
||||
for r in caplog.records
|
||||
)
|
||||
|
||||
def test_list_tel_on_no_existing_line_warns(self, caplog):
|
||||
"""Same warning behaviour for TEL — list input on a contact without an
|
||||
existing TEL line must not silently disappear.
|
||||
"""
|
||||
existing = "BEGIN:VCARD\nVERSION:3.0\nUID:merge-test\nFN:Alice\nEND:VCARD\n"
|
||||
with caplog.at_level("WARNING"):
|
||||
result = self._merge(
|
||||
existing, {"tel": [{"value": "555-9999", "type": ["WORK"]}]}
|
||||
)
|
||||
assert "TEL" not in result
|
||||
assert any(
|
||||
"tel" in r.message and "dict/list shape" in r.message
|
||||
for r in caplog.records
|
||||
)
|
||||
|
||||
def test_str_email_does_not_warn(self, caplog):
|
||||
"""Plain string email is the supported shape — no warning should fire."""
|
||||
existing = "BEGIN:VCARD\nVERSION:3.0\nUID:merge-test\nFN:Alice\nEND:VCARD\n"
|
||||
with caplog.at_level("WARNING"):
|
||||
result = self._merge(existing, {"email": "alice@work.com"})
|
||||
assert "EMAIL:alice@work.com" in result
|
||||
assert not any("dict/list shape" in r.message for r in caplog.records)
|
||||
|
||||
Reference in New Issue
Block a user