From ef552977738b66ded16a4c47acb9ebd60d0211d5 Mon Sep 17 00:00:00 2001 From: Julien Maupetit Date: Tue, 19 Nov 2024 17:16:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F(api)=20make=20`num=5Fpdl`?= =?UTF-8?q?=20field=20less=20provider-specific?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The num_pdl field is required to be a 14-characters string for Enedis (French provider) and forbids defining a num_pdl for other providers. Let's move to a more generic 64-chars string. --- src/api/CHANGELOG.md | 1 + src/api/qualicharge/models/static.py | 2 +- src/api/qualicharge/schemas/core.py | 2 +- src/api/tests/models/test_static.py | 12 ++++++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/CHANGELOG.md b/src/api/CHANGELOG.md index 72c347ee..d3d33dce 100644 --- a/src/api/CHANGELOG.md +++ b/src/api/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to - Upgrade pyjwt to `2.10.0` - Upgrade setuptools to `75.5.0` - Send DB query details on Statique API errors only in debug mode +- Move `num_pdl` field to a 64-chars string ## [0.14.0] - 2024-11-15 diff --git a/src/api/qualicharge/models/static.py b/src/api/qualicharge/models/static.py index 11c0aba4..eae78714 100644 --- a/src/api/qualicharge/models/static.py +++ b/src/api/qualicharge/models/static.py @@ -165,7 +165,7 @@ class Statique(ModelSchemaMixin, BaseModel): restriction_gabarit: str station_deux_roues: bool raccordement: Optional[RaccordementEnum] - num_pdl: Optional[Annotated[str, Field(pattern=r"^\d{14}$")]] + num_pdl: Optional[Annotated[str, Field(max_length=64)]] date_mise_en_service: Optional[PastDate] observations: Optional[str] date_maj: PastDate diff --git a/src/api/qualicharge/schemas/core.py b/src/api/qualicharge/schemas/core.py index 0f2ae090..1a4d8f44 100644 --- a/src/api/qualicharge/schemas/core.py +++ b/src/api/qualicharge/schemas/core.py @@ -236,7 +236,7 @@ class Station(BaseTimestampedSQLModel, table=True): horaires: str = Field(regex=r"(.*?)((\d{1,2}:\d{2})-(\d{1,2}:\d{2})|24/7)") station_deux_roues: bool raccordement: Optional[RaccordementEnum] - num_pdl: Optional[str] = Field(regex=r"^\d{14}$") + num_pdl: Optional[str] = Field(max_length=64) date_maj: PastDate = Field(sa_type=Date) date_mise_en_service: Optional[PastDate] = Field(sa_type=Date) diff --git a/src/api/tests/models/test_static.py b/src/api/tests/models/test_static.py index 31c02acb..353e75d2 100644 --- a/src/api/tests/models/test_static.py +++ b/src/api/tests/models/test_static.py @@ -94,3 +94,15 @@ def test_statique_model_afirev_previx_check(): # Default factory behavior should be consistent StatiqueFactory.build() + + +def test_statique_model_num_pdl(): + """Test statique model accept various num_pdf patterns.""" + statique = StatiqueFactory.build(num_pdl="0" * 14) + assert statique.num_pdl == "0" * 14 + + statique = StatiqueFactory.build(num_pdl="66666/E2/0000001") + assert statique.num_pdl == "66666/E2/0000001" + + with pytest.raises(ValueError, match="String should have at most 64 characters"): + StatiqueFactory.build(num_pdl="a" * 65)