Files
ldap2nextcloud/tests/test_model.py
T
zeguiguiandClaude Opus 5.5 35f90b8fb1 🤖 Recadrer les photos en carré autour du visage
Nextcloud et Android affichent la photo en carré découpé au milieu
d'une photo verticale, ce qui coupe les cheveux. La photo est
désormais recadrée en carré autour du visage, détecté localement par
YuNet (OpenCV, modèle MIT versionné dans le paquet) : les yeux sont
placés à la même hauteur sur toutes les photos. Sans visage détecté,
le carré est aligné en haut et compté dans le journal (-v).

Réglages dans mapping.yaml (fields.photo.crop : eyes_at, side, ou
false). Ils entrent dans l'empreinte des seules fiches avec photo :
celles-ci seront renvoyées une fois au prochain passage.

Les tests utilisent un visage généré par thispersondoesnotexist.com
(tests/data/README.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 19:13:45 +01:00

68 lines
2.3 KiB
Python

from dataclasses import replace
from datetime import date
from ldap2nextcloud.config import PhotoCrop
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)
def test_fingerprint_changes_with_crop_settings_when_contact_has_photo():
plain = fingerprint(BASE, 512, 80)
cropped = fingerprint(BASE, 512, 80, PhotoCrop())
assert plain != cropped
assert cropped != fingerprint(BASE, 512, 80, PhotoCrop(eyes_at=0.5))
assert cropped != fingerprint(BASE, 512, 80, PhotoCrop(side=6))
def test_crop_settings_do_not_touch_contacts_without_photo():
no_photo = replace(BASE, photo=None)
assert fingerprint(no_photo, 512, 80) == fingerprint(no_photo, 512, 80, PhotoCrop())