Skip to content

Commit

Permalink
fix broken go live email notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Nov 27, 2024
1 parent a1155df commit a5b83f5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 16 deletions.
6 changes: 0 additions & 6 deletions app/service/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
persist_notification,
send_notification_to_queue,
)
from app.utils import hilite


def send_notification_to_service_users(
Expand All @@ -25,12 +24,10 @@ def send_notification_to_service_users(
template = dao_get_template_by_id(template_id)
service = dao_fetch_service_by_id(service_id)
active_users = dao_fetch_active_users_for_service(service.id)
print(hilite(f"ACTIVE USERS ARE {active_users}"))
notify_service = dao_fetch_service_by_id(current_app.config["NOTIFY_SERVICE_ID"])

for user in active_users:
personalisation = _add_user_fields(user, personalisation, include_user_fields)
print(hilite(f"PERSONALISATION IS {personalisation}"))
notification = persist_notification(
template_id=template.id,
template_version=template.version,
Expand All @@ -46,17 +43,14 @@ def send_notification_to_service_users(
key_type=KeyType.NORMAL,
reply_to_text=notify_service.get_default_reply_to_email_address(),
)
print(hilite(f"NOTIFICATION IS {notification.serialize_for_csv()}"))
redis_store.set(
f"email-personalisation-{notification.id}",
json.dumps(personalisation),
ex=24 * 60 * 60,
)
print(hilite("GOT PAST FIRST SET"))
redis_store.set(
f"email-recipient-{notification.id}", notification.to, ex=24 * 60 * 60
)
print(hilite("GOT PAST SECOND SET"))

send_notification_to_queue(notification, queue=QueueNames.NOTIFY)

Expand Down
11 changes: 1 addition & 10 deletions tests/app/service/test_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from sqlalchemy import func, select

from app import db
from app.dao.services_dao import (
dao_add_user_to_service,
dao_fetch_active_users_for_service,
)
from app.dao.services_dao import dao_add_user_to_service
from app.enums import NotificationType, TemplateType
from app.models import Notification
from app.service.sender import send_notification_to_service_users
from app.utils import hilite
from tests.app.db import create_service, create_template, create_user


Expand Down Expand Up @@ -93,15 +89,10 @@ def test_send_notification_to_service_users_sends_to_active_users_only(
second_active_user = create_user(email="[email protected]", state="active")
pending_user = create_user(email="[email protected]", state="pending")
service = create_service(user=first_active_user)
print(hilite(f"CREATED THE SERVICE {service} with user {first_active_user}"))
dao_add_user_to_service(service, second_active_user)
print(hilite(f"ADDED user {second_active_user}"))

dao_add_user_to_service(service, pending_user)
print(hilite(f"ADDED PENDING USER {pending_user}"))

active_users = dao_fetch_active_users_for_service(service.id)
print(hilite(f"ACTIVE USERS IN THE TEST {active_users}"))
template = create_template(service, template_type=TemplateType.EMAIL)

send_notification_to_service_users(service_id=service.id, template_id=template.id)
Expand Down

0 comments on commit a5b83f5

Please sign in to comment.