Skip to content

Commit

Permalink
improves typng
Browse files Browse the repository at this point in the history
  • Loading branch information
hugobessa committed Dec 2, 2024
1 parent a17e6bb commit be38491
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions vintasend_django/services/notification_adapters/django_email.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Generic, TypeVar

from django.contrib.auth import get_user_model
from django.core.mail import EmailMessage
Expand All @@ -9,8 +9,9 @@
NotificationTemplateRenderingError,
)
from vintasend.services.dataclasses import Notification
from vintasend.services.helpers import get_notification_backend, get_template_renderer
from vintasend.services.notification_backends.base import BaseNotificationBackend
from vintasend.services.notification_adapters.base import BaseNotificationAdapter
from vintasend.services.notification_template_renderers.base_templated_email_renderer import BaseTemplatedEmailRenderer
from vintasend.app_settings import NotificationSettings


Expand All @@ -21,14 +22,11 @@
User = get_user_model()


class DjangoEmailNotificationAdapter(BaseNotificationAdapter):
notification_type = NotificationTypes.EMAIL
B = TypeVar("B", bound=BaseNotificationBackend)
T = TypeVar("T", bound=BaseTemplatedEmailRenderer)

def __init__(
self, template_renderer: str, backend: str | None, backend_kwargs: dict | None = None
) -> None:
self.backend = get_notification_backend(backend, backend_kwargs)
self.template_renderer = get_template_renderer(template_renderer)
class DjangoEmailNotificationAdapter(Generic[B, T], BaseNotificationAdapter[B, T]):
notification_type = NotificationTypes.EMAIL

def send(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@


class DjangoDbNotificationBackend(BaseNotificationBackend):
def __init__(self):
self.backend_kwargs = {}

def _get_all_future_notifications_queryset(self) -> QuerySet["NotificationModel"]:
return NotificationModel.objects.filter(
Q(send_after__gte=datetime.datetime.now()) | Q(send_after__isnull=False),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import uuid
import random
import pytest
from datetime import timedelta

Expand Down Expand Up @@ -71,7 +71,7 @@ def test_update_notification(self):

updated_notification = DjangoDbNotificationBackend().persist_notification_update(
notification_id=notification.id,
subject_template="updated test subject",
updated_data={"subject_template": "updated test subject"},
)

assert updated_notification.subject_template == "updated test subject"
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_get_pending_notifications(self):
)
DjangoDbNotificationBackend().persist_notification_update(
notification_id=already_sent.id,
status=NotificationStatus.SENT.value,
updated_data={"status": NotificationStatus.SENT.value},
)

notifications = list(
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_get_notification(self):

def test_get_notification_not_found(self):
with pytest.raises(NotificationNotFoundError):
DjangoDbNotificationBackend().get_notification(uuid.uuid4())
DjangoDbNotificationBackend().get_notification(random.randint(1, 100))

def test_get_notification_cancelled(self):
notification = DjangoDbNotificationBackend().persist_notification(
Expand Down

0 comments on commit be38491

Please sign in to comment.