feat(logging): seed template_entry_updated event (#27)
This commit is contained in:
parent
0b6bc126d7
commit
ea9e76d090
2 changed files with 27 additions and 1 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
logger = logging.getLogger("quartermaster.service")
|
||||||
|
|
||||||
from quartermaster.groups import (
|
from quartermaster.groups import (
|
||||||
GROUP_DEFAULT_OPEN,
|
GROUP_DEFAULT_OPEN,
|
||||||
GROUP_LABELS,
|
GROUP_LABELS,
|
||||||
|
|
@ -134,6 +137,10 @@ def update_entry(
|
||||||
entry.notes = _clean_notes(notes) # type: ignore[arg-type]
|
entry.notes = _clean_notes(notes) # type: ignore[arg-type]
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(entry)
|
db.refresh(entry)
|
||||||
|
logger.info(
|
||||||
|
"updated template entry",
|
||||||
|
extra={"event": "template_entry_updated", "entry_id": entry.id},
|
||||||
|
)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from decimal import Decimal
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from quartermaster import month_service
|
from quartermaster import month_service, service
|
||||||
from quartermaster.logging_config import LOG_CONFIG
|
from quartermaster.logging_config import LOG_CONFIG
|
||||||
from quartermaster.models import Section
|
from quartermaster.models import Section
|
||||||
|
|
||||||
|
|
@ -169,3 +169,22 @@ def test_delete_posting_logs_posting_deleted_event(db, caplog):
|
||||||
|
|
||||||
events = [r for r in caplog.records if getattr(r, "event", None) == "posting_deleted"]
|
events = [r for r in caplog.records if getattr(r, "event", None) == "posting_deleted"]
|
||||||
assert len(events) == 1
|
assert len(events) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_entry_logs_template_entry_updated_event(db, caplog):
|
||||||
|
from quartermaster.models import Entry
|
||||||
|
entry = Entry(section=Section.fixed_bill, name="Power", amount=Decimal("50.00"))
|
||||||
|
db.add(entry)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(entry)
|
||||||
|
|
||||||
|
caplog.set_level(logging.INFO, logger="quartermaster")
|
||||||
|
|
||||||
|
service.update_entry(db, entry.id, amount=Decimal("55.00"))
|
||||||
|
|
||||||
|
events = [
|
||||||
|
r for r in caplog.records
|
||||||
|
if getattr(r, "event", None) == "template_entry_updated"
|
||||||
|
]
|
||||||
|
assert len(events) == 1
|
||||||
|
assert events[0].entry_id == entry.id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue