api_entreprise: fix mandataires’ first names possible delimiters (#76737)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b3dfbd17df
commit
6d55216e43
|
@ -27,7 +27,7 @@ def normalize(s):
|
|||
def simple_match(mandataire, first_name, last_name, birthdate):
|
||||
if any([attr not in mandataire for attr in ['prenom', 'nom', 'date_naissance']]):
|
||||
return False
|
||||
if normalize(mandataire['prenom'].split(',')[0]) != normalize(first_name):
|
||||
if normalize(mandataire['prenom'].replace(',', ' ').split(maxsplit=1)[0]) != normalize(first_name):
|
||||
return False
|
||||
if normalize(mandataire['nom']) != normalize(last_name):
|
||||
return False
|
||||
|
@ -41,7 +41,12 @@ def levenshtein_match(mandataire, first_name, last_name, birthdate):
|
|||
return False
|
||||
dist_first_name = min(2, int(len(first_name) / 4))
|
||||
dist_last_name = min(2, int(len(last_name) / 4))
|
||||
if ldistance(normalize(mandataire['prenom'].split(',')[0]), normalize(first_name)) > dist_first_name:
|
||||
if (
|
||||
ldistance(
|
||||
normalize(mandataire['prenom'].replace(',', ' ').split(maxsplit=1)[0]), normalize(first_name)
|
||||
)
|
||||
> dist_first_name
|
||||
):
|
||||
return False
|
||||
if ldistance(normalize(mandataire['nom']), normalize(last_name)) > dist_last_name:
|
||||
return False
|
||||
|
|
|
@ -122,7 +122,7 @@ RCS_UNITES_LEGALES_MANDATAIRES_SOCIAUX_RESPONSE = {
|
|||
{
|
||||
"data": {
|
||||
"nom": "HISQUIN",
|
||||
"prenom": "FRANCOIS",
|
||||
"prenom": "FRANCOIS CARLOS PIOTR",
|
||||
"fonction": "PRESIDENT DU DIRECTOIRE",
|
||||
"dirigeant": True,
|
||||
"date_naissance": "1965-01-27",
|
||||
|
@ -131,6 +131,19 @@ RCS_UNITES_LEGALES_MANDATAIRES_SOCIAUX_RESPONSE = {
|
|||
"type": "PP",
|
||||
},
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"nom": "MICHU",
|
||||
"prenom": "ETIENNE,ALI,CLAY",
|
||||
"fonction": "FIGURANT LDIF",
|
||||
"dirigeant": True,
|
||||
"date_naissance": "1969-08-15",
|
||||
"date_naissance_timestamp": 0,
|
||||
"raison_sociale": "BCRH & ASSOCIES - SOCIETE A RESPONSABILITE LIMITEE A ASSOCIE UNIQUE",
|
||||
"identifiant": "490092574",
|
||||
"type": "PP",
|
||||
},
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"fonction": "COMMISSAIRE AUX COMPTES SUPPLEANT",
|
||||
|
@ -293,11 +306,11 @@ def test_entreprises_endpoint(app, resource):
|
|||
mandataires_sociaux = data['entreprise']['mandataires_sociaux']
|
||||
assert mandataires_sociaux[0]['date_naissance'] == '1965-01-27'
|
||||
assert mandataires_sociaux[0]['nom'] == 'HISQUIN'
|
||||
assert mandataires_sociaux[0]['prenom'] == 'FRANCOIS'
|
||||
assert mandataires_sociaux[0]['prenom'] == 'FRANCOIS CARLOS PIOTR'
|
||||
assert mandataires_sociaux[0]['fonction'] == 'PRESIDENT DU DIRECTOIRE'
|
||||
assert mandataires_sociaux[1]['nom'] == ''
|
||||
assert mandataires_sociaux[1]['prenom'] == ''
|
||||
assert mandataires_sociaux[1]['fonction'] == 'COMMISSAIRE AUX COMPTES SUPPLEANT'
|
||||
assert mandataires_sociaux[1]['nom'] == 'MICHU'
|
||||
assert mandataires_sociaux[1]['prenom'] == 'ETIENNE,ALI,CLAY'
|
||||
assert mandataires_sociaux[1]['fonction'] == 'FIGURANT LDIF'
|
||||
|
||||
assert 'etablissement_siege' in data
|
||||
assert data['etablissement_siege']['siret'] == '41816609600051'
|
||||
|
@ -334,7 +347,7 @@ def test_simple_match_mandataire_social(app, resource):
|
|||
# successful matching
|
||||
data = response.json['data']
|
||||
assert data['nom'] == 'HISQUIN'
|
||||
assert data['prenom'] == 'FRANCOIS'
|
||||
assert data['prenom'] == 'FRANCOIS CARLOS PIOTR'
|
||||
assert data['date_naissance'] == '1965-01-27'
|
||||
assert data['type'] == 'PP'
|
||||
|
||||
|
@ -360,6 +373,20 @@ def test_simple_match_mandataire_social(app, resource):
|
|||
assert not response.json['err']
|
||||
assert not response.json['data']
|
||||
|
||||
params['first_name'] = 'etienne'
|
||||
params['last_name'] = 'MichU'
|
||||
params['birthdate'] = '19690815'
|
||||
params['method'] = 'simple'
|
||||
|
||||
response = app.get(url, params=params)
|
||||
|
||||
# successful matching with comma-separated first names
|
||||
data = response.json['data']
|
||||
assert data['nom'] == 'MICHU'
|
||||
assert data['prenom'] == 'ETIENNE,ALI,CLAY'
|
||||
assert data['date_naissance'] == '1969-08-15'
|
||||
assert data['type'] == 'PP'
|
||||
|
||||
|
||||
def test_levenshtein_match_mandataire_social(app, resource):
|
||||
params = {
|
||||
|
@ -382,7 +409,7 @@ def test_levenshtein_match_mandataire_social(app, resource):
|
|||
# successful matching
|
||||
data = response.json['data']
|
||||
assert data['nom'] == 'HISQUIN'
|
||||
assert data['prenom'] == 'FRANCOIS'
|
||||
assert data['prenom'] == 'FRANCOIS CARLOS PIOTR'
|
||||
assert data['date_naissance'] == '1965-01-27'
|
||||
assert data['type'] == 'PP'
|
||||
|
||||
|
@ -400,10 +427,23 @@ def test_levenshtein_match_mandataire_social(app, resource):
|
|||
# successful matching within distance bracket
|
||||
data = response.json['data']
|
||||
assert data['nom'] == 'HISQUIN'
|
||||
assert data['prenom'] == 'FRANCOIS'
|
||||
assert data['prenom'] == 'FRANCOIS CARLOS PIOTR'
|
||||
assert data['date_naissance'] == '1965-01-27'
|
||||
assert data['type'] == 'PP'
|
||||
|
||||
params['first_name'] = 'etienn'
|
||||
params['last_name'] = 'Michui'
|
||||
params['birthdate'] = '19690815'
|
||||
|
||||
response = app.get(url, params=params)
|
||||
|
||||
# successful matching with distance bracket, with comma-separated first names
|
||||
data = response.json['data']
|
||||
assert data['nom'] == 'MICHU'
|
||||
assert data['prenom'] == 'ETIENNE,ALI,CLAY'
|
||||
assert data['date_naissance'] == '1969-08-15'
|
||||
assert data['type'] == 'PP'
|
||||
|
||||
|
||||
def test_entreprises_endpoint_include_private(app, resource):
|
||||
with responses.RequestsMock() as rsps:
|
||||
|
|
Loading…
Reference in New Issue