This commit is contained in:
Kenneth Kehl
2024-10-31 11:32:27 -07:00
parent 6b6bc2b4e7
commit bc7180185b
9 changed files with 74 additions and 28 deletions

View File

@@ -42,12 +42,17 @@ def test_move_notifications_does_nothing_if_notification_history_row_already_exi
1,
)
assert Notification.query.count() == 0
assert _get_notification_count() == 0
history = NotificationHistory.query.all()
assert len(history) == 1
assert history[0].status == NotificationStatus.DELIVERED
def _get_notification_count():
stmt = select(func.count()).select_from(Notification)
return db.session.execute(stmt).scalar() or 0
def test_move_notifications_only_moves_notifications_older_than_provided_timestamp(
sample_template,
):
@@ -172,8 +177,10 @@ def test_move_notifications_just_deletes_test_key_notifications(sample_template)
assert result == 2
assert Notification.query.count() == 0
assert NotificationHistory.query.count() == 2
assert _get_notification_count() == 0
stmt = select(func.count()).select_from(NotificationHistory)
count = db.session.execute(stmt).scalar() or 0
assert count == 2
stmt = (
select(func.count())
.select_from(NotificationHistory)

View File

@@ -1,9 +1,14 @@
from sqlalchemy import func, select
from app import db
from app.dao.events_dao import dao_create_event
from app.models import Event
def test_create_event(notify_db_session):
assert Event.query.count() == 0
stmt = select(func.count()).select_from(Event)
count = db.session.execute(stmt).scalar() or 0
assert count == 0
data = {
"event_type": "sucessful_login",
"data": {"something": "random", "in_fact": "could be anything"},
@@ -12,6 +17,8 @@ def test_create_event(notify_db_session):
event = Event(**data)
dao_create_event(event)
assert Event.query.count() == 1
stmt = select(func.count()).select_from(Event)
count = db.session.execute(stmt).scalar() or 0
assert count == 1
event_from_db = Event.query.first()
assert event == event_from_db