Skip to content

Commit

Permalink
🐛(api) commit session when refreshing the Statique MV
Browse files Browse the repository at this point in the history
Oopsie!
  • Loading branch information
jmaupetit committed Jan 29, 2025
1 parent fb79f48 commit c18a0c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/api/cron.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"jobs": [
{
"command": "*/10 * * * * python -m qualicharge refresh-static"
"command": "*/10 * * * * python -m qualicharge refresh-static --concurrently"
}
]
}
2 changes: 2 additions & 0 deletions src/api/qualicharge/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def refresh_static(ctx: typer.Context, concurrently: bool = False):
refresh_materialized_view(
session, STATIQUE_MV_TABLE_NAME, concurrently=concurrently
)
session.commit()
console.log("Statique Materalized View has been refreshed.")


@app.callback()
Expand Down
15 changes: 15 additions & 0 deletions src/api/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
OperationalUnit,
PointDeCharge,
Station,
StatiqueMV,
)
from qualicharge.schemas.utils import save_statiques


def test_list_groups(runner, db_session):
Expand Down Expand Up @@ -505,3 +507,16 @@ def test_import_static_with_integrity_exception(runner, db_session):
assert db_session.exec(select(func.count(Operateur.id))).one() == 0
assert db_session.exec(select(func.count(PointDeCharge.id))).one() == 0
assert db_session.exec(select(func.count(Station.id))).one() == 0


def test_refresh_static(runner, db_session):
"""Test the `refresh-static` command."""
# Create points of charge
n_pdc = 4
save_statiques(db_session, StatiqueFactory.batch(n_pdc))
assert db_session.exec(select(func.count(StatiqueMV.pdc_id))).one() == 0

# Proceed
result = runner.invoke(app, ["refresh-static", "--concurrently"], obj=db_session)
assert result.exit_code == 0
assert db_session.exec(select(func.count(StatiqueMV.pdc_id))).one() == n_pdc

0 comments on commit c18a0c0

Please sign in to comment.