Skip to content

Commit

Permalink
Remove notification fallback (#2107)
Browse files Browse the repository at this point in the history
* Remove notification fallback

* fix
  • Loading branch information
jzbahrai authored Feb 6, 2024
1 parent 0d5cce4 commit 5aeb39c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 29 deletions.
9 changes: 1 addition & 8 deletions app/dao/fact_notification_status_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,7 @@ def get_last_send_for_api_key(api_key_id):
api_key_table = (
db.session.query(ApiKey.last_used_timestamp.label("last_notification_created")).filter(ApiKey.id == api_key_id).all()
)
if not api_key_table[0][0]:
notification_table = (
db.session.query(func.max(Notification.created_at).label("last_notification_created"))
.filter(Notification.api_key_id == api_key_id)
.all()
)
return [] if notification_table[0][0] is None else notification_table
return api_key_table
return [] if api_key_table[0][0] is None else api_key_table


def get_api_key_ranked_by_notifications_created(n_days_back):
Expand Down
9 changes: 0 additions & 9 deletions tests/app/api_key/test_rest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from datetime import datetime

import pytest
from flask import url_for

from app import DATETIME_FORMAT
from app.dao.api_key_dao import get_api_key_by_secret, get_unsigned_secret
from app.models import KEY_TYPE_NORMAL
from tests import create_sre_authorization_header
Expand Down Expand Up @@ -33,12 +30,6 @@ def test_get_api_key_stats_with_sends(admin_request, notify_db, notify_db_sessio
assert api_key_stats["sms_sends"] == 0
assert api_key_stats["total_sends"] == total_sends

# the following lines test that a send has occurred within the last second
last_send_dt = datetime.strptime(api_key_stats["last_send"], DATETIME_FORMAT)
now = datetime.utcnow()
time_delta = now - last_send_dt
assert abs(time_delta.total_seconds()) < 1


def test_get_api_key_stats_no_sends(admin_request, notify_db, notify_db_session):
service = create_service(service_name="Service 2")
Expand Down
12 changes: 0 additions & 12 deletions tests/app/dao/test_fact_notification_status_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,9 @@ def test_get_last_send_for_api_key_check_last_used(notify_db_session):
def test_get_last_send_for_api_key(notify_db_session):
service = create_service(service_name="First Service")
api_key = create_api_key(service)
template_email = create_template(service=service, template_type=EMAIL_TYPE)
total_sends = 10

last_send = get_last_send_for_api_key(str(api_key.id))
assert last_send == []

for x in range(total_sends):
save_notification(create_notification(template=template_email, api_key=api_key))

# the following lines test that a send has occurred within the last second
last_send = get_last_send_for_api_key(str(api_key.id))[0][0]
now = datetime.utcnow()
time_delta = now - last_send
assert abs(time_delta.total_seconds()) < 1


def test_get_api_key_ranked_by_notifications_created(notify_db_session):
service = create_service(service_name="Service 1")
Expand Down

0 comments on commit 5aeb39c

Please sign in to comment.