-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'section activaté principle' filter to API
Merge pull request #35 from etalab/sections-NAF
- Loading branch information
Showing
7 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"A":"Agriculture, sylviculture et pêche", | ||
"B":"Industries extractives", | ||
"C":"Industrie manufacturière", | ||
"D":"Production et distribution d'électricité, de gaz, de vapeur et d'air conditionné", | ||
"E":"Production et distribution d'eau ; assainissement, gestion des déchets et dépollution", | ||
"F":"Construction", | ||
"G":"Commerce; réparation d'automobiles et de motocycles", | ||
"H":"Transports et entreposage", | ||
"I":"Hébergement et restauration", | ||
"J":"Information et communication", | ||
"K":"Activités financières et d'assurance", | ||
"L":"Activités immobilières", | ||
"M":"Activités spécialisées, scientifiques et techniques", | ||
"N":"Activités de services administratifs et de soutien", | ||
"O":"Administration publique", | ||
"P":"Enseignement", | ||
"Q":"Santé humaine et action sociale", | ||
"R":"Arts, spectacles et activités récréatives", | ||
"S":"Autres activités de services", | ||
"T":"Activités des ménages en tant qu'employeurs ; activités indifférenciées des ménages en tant que producteurs de biens et services pour usage propre", | ||
"U":"Activités extra-territoriales" | ||
} |
26 changes: 26 additions & 0 deletions
26
aio/aio-proxy/aio_proxy/parsers/section_activite_principale.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Optional | ||
|
||
from aio_proxy.labels.helpers import sections_codes_naf | ||
|
||
|
||
def validate_section_activite_principale( | ||
section_activite_principale_clean: str, | ||
) -> Optional[str]: | ||
"""Check the validity of section_activite_principale. | ||
Args: | ||
section_activite_principale_clean(str, optional): | ||
section_activite_principale extracted and cleaned. | ||
Returns: | ||
None if section_activite_principale_clean is None. | ||
section_activite_principale_clean if valid. | ||
Raises: | ||
ValueError: if section_activite_principale_clean not valid. | ||
""" | ||
if section_activite_principale_clean is None: | ||
return None | ||
if section_activite_principale_clean not in sections_codes_naf: | ||
raise ValueError("Section d'activité principale non valide.") | ||
return section_activite_principale_clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
aio/aio-proxy/aio_proxy/tests/test_section_activite_principale.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import pytest | ||
from aio_proxy.parsers.section_activite_principale import ( | ||
validate_section_activite_principale, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"section_activite_principale, expected", | ||
[("A", "A"), (None, None)], | ||
) | ||
def test_validate_section_activite_principale( | ||
section_activite_principale: str, expected: str | ||
): | ||
assert validate_section_activite_principale(section_activite_principale) == expected | ||
|
||
|
||
@pytest.mark.parametrize("section_activite_principale", ["Z", "68.20B"]) | ||
def test_validate_section_activite_principale_fail( | ||
section_activite_principale: str, | ||
): | ||
with pytest.raises(ValueError, match="Section d'activité principale non valide."): | ||
validate_section_activite_principale(section_activite_principale) |