Historique regroupé en un seul commit pour ne pas publier de données de production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from dataclasses import replace
|
|
from datetime import date
|
|
|
|
from ldap2nextcloud.model import Contact, Email, Phone, contact_href, contact_uid, fingerprint
|
|
|
|
BASE = Contact(
|
|
key="omalmare",
|
|
given_name="Oscar",
|
|
family_name="MALMARE",
|
|
full_name="MALMARE Oscar",
|
|
organization="Exemple",
|
|
title="Ingénieur",
|
|
emails=(Email("o.malmare@example.org", "work", True),),
|
|
phones=(Phone("+33123459052", "work"),),
|
|
category="Direction des systèmes d'information",
|
|
birthday=date(1968, 6, 15),
|
|
photo=b"\xff\xd8photo",
|
|
)
|
|
|
|
|
|
def test_href_is_stable_and_derived_from_key():
|
|
assert contact_href("omalmare") == contact_href("omalmare")
|
|
assert contact_href("omalmare") == f"{contact_uid('omalmare')}.vcf"
|
|
assert contact_href("omalmare") != contact_href("cbarssac")
|
|
|
|
|
|
def test_uid_is_known_uuid5():
|
|
# Valeur figée : changer le namespace casserait l'identité de toutes les fiches.
|
|
assert contact_uid("omalmare") == contact_uid("omalmare")
|
|
assert len(contact_uid("omalmare")) == 36
|
|
assert contact_uid("omalmare")[14] == "5"
|
|
|
|
|
|
def test_fingerprint_stable_for_equal_contacts():
|
|
assert fingerprint(BASE, 512, 80) == fingerprint(replace(BASE), 512, 80)
|
|
|
|
|
|
def test_fingerprint_changes_with_any_field():
|
|
reference = fingerprint(BASE, 512, 80)
|
|
for changed in (
|
|
replace(BASE, category="Autre"),
|
|
replace(BASE, photo=b"autre"),
|
|
replace(BASE, photo=None),
|
|
replace(BASE, birthday=None),
|
|
replace(BASE, phones=()),
|
|
replace(BASE, title="Chef"),
|
|
):
|
|
assert fingerprint(changed, 512, 80) != reference
|
|
|
|
|
|
def test_fingerprint_changes_with_photo_settings():
|
|
assert fingerprint(BASE, 512, 80) != fingerprint(BASE, 720, 80)
|
|
assert fingerprint(BASE, 512, 80) != fingerprint(BASE, 512, 90)
|