-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: implement create status API endpoint
- Loading branch information
Showing
2 changed files
with
74 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Tests for the QualiCharge API dynamic router.""" | ||
|
||
import json | ||
|
||
from fastapi import status | ||
from sqlmodel import select | ||
|
||
from qualicharge.factories.dynamic import StatusCreateFactory | ||
from qualicharge.factories.static import StatiqueFactory | ||
from qualicharge.schemas import PointDeCharge, Status | ||
from qualicharge.schemas.utils import save_statique | ||
|
||
|
||
def test_create_status_with_invalid_id_pdc_itinerance(db_session, client_auth): | ||
"""Test the /status/ create endoiint.""" | ||
id_pdc_itinerance = "ESZUNE1111ER1" | ||
qc_status = StatusCreateFactory.build(id_pdc_itinerance=id_pdc_itinerance) | ||
|
||
# Point of charge does not exist yet | ||
response = client_auth.post( | ||
"/dynamique/status/", json=json.loads(qc_status.model_dump_json()) | ||
) | ||
assert response.status_code == status.HTTP_404_NOT_FOUND | ||
assert response.json() == {"detail": "Attached point of charge does not exist"} | ||
|
||
# Create point of charge | ||
save_statique( | ||
db_session, StatiqueFactory.build(id_pdc_itinerance=id_pdc_itinerance) | ||
) | ||
response = client_auth.post( | ||
"/dynamique/status/", json=json.loads(qc_status.model_dump_json()) | ||
) | ||
assert response.status_code == status.HTTP_201_CREATED | ||
assert response.json() is None | ||
|
||
# Query database to check created status and relations | ||
pdc = db_session.exec( | ||
select(PointDeCharge).where( | ||
PointDeCharge.id_pdc_itinerance == qc_status.id_pdc_itinerance | ||
) | ||
).one() | ||
db_status = db_session.exec(select(Status)).one() | ||
assert db_status.point_de_charge_id == pdc.id | ||
assert db_status in pdc.statuses |