2024-10-31 11:32:27 -07:00
|
|
|
from sqlalchemy import func, select
|
|
|
|
|
|
|
|
|
|
from app import db
|
2016-04-27 10:27:05 +01:00
|
|
|
from app.dao.events_dao import dao_create_event
|
|
|
|
|
from app.models import Event
|
|
|
|
|
|
|
|
|
|
|
2022-05-03 17:00:51 +01:00
|
|
|
def test_create_event(notify_db_session):
|
2024-10-31 11:32:27 -07:00
|
|
|
stmt = select(func.count()).select_from(Event)
|
|
|
|
|
count = db.session.execute(stmt).scalar() or 0
|
|
|
|
|
assert count == 0
|
2016-04-27 10:27:05 +01:00
|
|
|
data = {
|
2023-08-29 14:54:30 -07:00
|
|
|
"event_type": "sucessful_login",
|
|
|
|
|
"data": {"something": "random", "in_fact": "could be anything"},
|
2016-04-27 10:27:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event = Event(**data)
|
|
|
|
|
dao_create_event(event)
|
|
|
|
|
|
2024-10-31 11:32:27 -07:00
|
|
|
stmt = select(func.count()).select_from(Event)
|
|
|
|
|
count = db.session.execute(stmt).scalar() or 0
|
|
|
|
|
assert count == 1
|
2024-11-18 10:35:54 -08:00
|
|
|
event_from_db = db.session.execute(select(Event)).scalars().first()
|
2016-04-27 10:27:05 +01:00
|
|
|
assert event == event_from_db
|