🤖 Option pour écarter les fiches sans Direction ni téléphone
Avec skip_without_group_and_phone: true dans mapping.yaml, une fiche dont l'attribut Direction est vide et qui n'a aucun téléphone n'est pas synchronisée (et est supprimée du carnet si elle y est). Un code Direction inconnu de directions.yaml ne compte pas comme vide. L'option est désactivée par défaut ; le nombre de fiches écartées est journalisé. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
35f90b8fb1
commit
6d8ec287ec
8 files changed
+102
-4
No files matched your search
+33
-1
@@ -3,7 +3,9 @@ from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from ldap2nextcloud.config import PhoneRule, load_directions, load_mapping
|
||||
from ldap2nextcloud.mapping import entry_to_contact, format_phone, parse_birthday
|
||||
from dataclasses import replace
|
||||
|
||||
from ldap2nextcloud.mapping import entry_to_contact, format_phone, is_excluded, parse_birthday
|
||||
from ldap2nextcloud.model import Email, Phone
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -111,3 +113,33 @@ def test_full_name_fallback_without_cn():
|
||||
def test_preferred_email_domain():
|
||||
c = entry_to_contact(entry(mail=["x@autre.fr", "x@example.org"]), MAPPING, DIRECTIONS, True)
|
||||
assert c.emails == (Email("x@example.org", "work", True), Email("x@autre.fr", "work", False))
|
||||
|
||||
|
||||
# --- Fiches écartées : ni Direction ni téléphone -----------------------------
|
||||
|
||||
STRICT = replace(MAPPING, skip_without_group_and_phone=True)
|
||||
|
||||
|
||||
def test_entry_without_direction_nor_phone_is_excluded():
|
||||
assert is_excluded(entry(usrDirectionId=None, telephoneNumber=None), STRICT)
|
||||
|
||||
|
||||
def test_blank_direction_counts_as_missing():
|
||||
assert is_excluded(entry(usrDirectionId=[" "], telephoneNumber=[""]), STRICT)
|
||||
|
||||
|
||||
def test_entry_with_phone_but_no_direction_is_kept():
|
||||
assert not is_excluded(entry(usrDirectionId=None), STRICT)
|
||||
|
||||
|
||||
def test_entry_with_direction_but_no_phone_is_kept():
|
||||
assert not is_excluded(entry(telephoneNumber=None), STRICT)
|
||||
|
||||
|
||||
def test_unknown_direction_code_is_not_an_empty_direction():
|
||||
assert not is_excluded(entry(usrDirectionId=["999"], telephoneNumber=None), STRICT)
|
||||
|
||||
|
||||
def test_rule_is_off_by_default():
|
||||
assert not MAPPING.skip_without_group_and_phone
|
||||
assert not is_excluded(entry(usrDirectionId=None, telephoneNumber=None), MAPPING)
|
||||
Reference in new issue
Block a user