Skip to content

Commit

Permalink
renate notification metadata to adapter_extra_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Dec 21, 2024
1 parent 6fc2241 commit 86356fb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions vintasend/services/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Notification:
preheader_template: str
status: str
context_used: dict | None = None
metadata: dict | None = None
adapter_used: str | None = None
adapter_extra_parameters: dict | None = None


class UpdateNotificationKwargs(TypedDict, total=False):
Expand All @@ -79,4 +80,4 @@ class UpdateNotificationKwargs(TypedDict, total=False):
send_after: datetime.datetime | None
subject_template: str | None
preheader_template: str | None
metadata: dict | None
adapter_extra_parameters: dict | None
2 changes: 1 addition & 1 deletion vintasend/services/notification_adapters/async_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NotificationDict(TypedDict):
preheader_template: str
status: str
context_used: dict | None
metadata: dict | None
adapter_extra_parameters: dict | None


@runtime_checkable
Expand Down
2 changes: 1 addition & 1 deletion vintasend/services/notification_backends/asyncio_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def persist_notification(
send_after: datetime.datetime | None,
subject_template: str,
preheader_template: str,
metadata: dict | None = None,
adapter_extra_parameters: dict | None = None,
lock: asyncio.Lock | None = None
) -> "Notification":
...
Expand Down
2 changes: 1 addition & 1 deletion vintasend/services/notification_backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def persist_notification(
send_after: datetime.datetime | None,
subject_template: str,
preheader_template: str,
metadata: dict | None = None,
adapter_extra_parameters: dict | None = None,
) -> "Notification":
raise NotImplementedError

Expand Down
12 changes: 6 additions & 6 deletions vintasend/services/notification_backends/stubs/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _convert_notification_to_json(self, notification: Notification) -> dict:
"preheader_template": notification.preheader_template,
"status": notification.status,
"context_used": notification.context_used,
"metadata": notification.metadata,
"adapter_extra_parameters": notification.adapter_extra_parameters,
}

def _convert_json_to_notification(self, notification: dict) -> Notification:
Expand All @@ -106,7 +106,7 @@ def _convert_json_to_notification(self, notification: dict) -> Notification:
preheader_template=notification["preheader_template"],
status=notification["status"],
context_used=notification.get("context_used"),
metadata=notification.get("metadata"),
adapter_extra_parameters=notification.get("adapter_extra_parameters"),
)

def _store_notifications(self):
Expand Down Expand Up @@ -134,7 +134,7 @@ def persist_notification(
send_after: datetime.datetime | None,
subject_template: str,
preheader_template: str,
metadata: dict | None = None,
adapter_extra_parameters: dict | None = None,
) -> Notification:
notification = Notification(
id=str(uuid.uuid4()),
Expand All @@ -148,7 +148,7 @@ def persist_notification(
subject_template=subject_template,
preheader_template=preheader_template,
status=NotificationStatus.PENDING_SEND.value,
metadata=metadata,
adapter_extra_parameters=adapter_extra_parameters,
)
self.notifications.append(notification)
self._store_notifications()
Expand Down Expand Up @@ -377,7 +377,7 @@ async def persist_notification(
send_after: datetime.datetime | None,
subject_template: str,
preheader_template: str,
metadata: dict | None = None,
adapter_extra_parameters: dict | None = None,
lock: asyncio.Lock | None = None,
) -> Notification:
notification = Notification(
Expand All @@ -392,7 +392,7 @@ async def persist_notification(
subject_template=subject_template,
preheader_template=preheader_template,
status=NotificationStatus.PENDING_SEND.value,
metadata=metadata,
adapter_extra_parameters=adapter_extra_parameters,
)
self.notifications.append(notification)
await self._store_notifications(lock)
Expand Down
6 changes: 4 additions & 2 deletions vintasend/services/notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def create_notification(
send_after: datetime.datetime | None = None,
subject_template: str = "",
preheader_template: str = "",
metadata: dict | None = None,
adapter_extra_parameters: dict | None = None,
) -> Notification:
"""
Create a notification and send it if it is due to be sent immediately.
Expand Down Expand Up @@ -254,7 +254,7 @@ def create_notification(
send_after=send_after,
subject_template=subject_template,
preheader_template=preheader_template,
metadata=metadata,
adapter_extra_parameters=adapter_extra_parameters,
)
if notification.send_after is None or notification.send_after <= datetime.datetime.now(
tz=datetime.timezone.utc
Expand Down Expand Up @@ -667,6 +667,7 @@ async def create_notification(
send_after: datetime.datetime | None = None,
subject_template: str = "",
preheader_template: str = "",
adapter_extra_parameters: dict | None = None,
) -> Notification:
"""
Create a notification and send it if it is due to be sent immediately.
Expand Down Expand Up @@ -698,6 +699,7 @@ async def create_notification(
send_after=send_after,
subject_template=subject_template,
preheader_template=preheader_template,
adapter_extra_parameters=adapter_extra_parameters,
)
if notification.send_after is None or notification.send_after <= datetime.datetime.now(
tz=datetime.timezone.utc
Expand Down
2 changes: 1 addition & 1 deletion vintasend/tests/test_services/test_notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def notification_to_dict(notification: "Notification") -> NotificationDict:
preheader_template=notification.preheader_template,
status=notification.status,
context_used=notification.context_used,
metadata=notification.metadata,
adapter_extra_parameters=notification.adapter_extra_parameters,
)

class NotificationServiceTestCase(TestCase):
Expand Down

0 comments on commit 86356fb

Please sign in to comment.