Merge pull request #704 from GSA/API-312_Make_Multiple_Opt_Out_Lists_Pinpoint

Clean up client classes
This commit is contained in:
Carlo Costino
2024-01-04 15:52:00 -05:00
committed by GitHub
6 changed files with 29 additions and 12 deletions

View File

@@ -1,3 +1,6 @@
from abc import abstractmethod
from typing import Protocol
from botocore.config import Config
AWS_CLIENT_CONFIG = Config(
@@ -22,12 +25,14 @@ class ClientException(Exception):
pass
class Client(object):
class Client(Protocol):
"""
Base client for sending notifications.
"""
pass
@abstractmethod
def init_app(self, current_app, *args, **kwargs):
raise NotImplementedError("TODO: Need to implement.")
class NotificationProviderClients(object):

View File

@@ -1,3 +1,5 @@
from abc import abstractmethod, abstractproperty
from app.clients import Client, ClientException
@@ -27,9 +29,10 @@ class EmailClient(Client):
Base Email client for sending emails.
"""
@abstractmethod
def send_email(self, *args, **kwargs):
raise NotImplementedError("TODO Need to implement.")
@property
@abstractproperty
def name(self):
raise NotImplementedError("TODO Need to implement.")

View File

@@ -10,7 +10,7 @@ class PerformancePlatformClient:
def active(self):
return self._active
def init_app(self, app):
def init_app(self, app, *args, **kwargs):
self._active = app.config.get("PERFORMANCE_PLATFORM_ENABLED")
if self.active:
self.performance_platform_url = app.config.get("PERFORMANCE_PLATFORM_URL")

View File

@@ -1,3 +1,6 @@
from abc import abstractmethod, abstractproperty
from typing import final
from app.clients import Client, ClientException
@@ -10,7 +13,7 @@ class SmsClientResponseException(ClientException):
self.message = message
def __str__(self):
return "Message {}".format(self.message)
return f"Message {self.message}"
class SmsClient(Client):
@@ -18,11 +21,14 @@ class SmsClient(Client):
Base Sms client for sending smss.
"""
def init_app(self, *args, **kwargs):
raise NotImplementedError("TODO Need to implement.")
@abstractmethod
def send_sms(self, *args, **kwargs):
raise NotImplementedError("TODO Need to implement.")
def get_name(self):
@abstractproperty
def name(self):
raise NotImplementedError("TODO Need to implement.")
@final
def get_name(self):
return self.name

View File

@@ -43,9 +43,6 @@ class AwsSnsClient(SmsClient):
def name(self):
return "sns"
def get_name(self):
return self.name
def _valid_sender_number(self, sender):
return sender and re.match(self._valid_sender_regex, sender)

View File

@@ -10,6 +10,12 @@ def fake_client(notify_api):
def name(self):
return "fake"
def init_app(self, current_app, *args, **kwargs):
pass
def send_sms(self, *args, **kwargs):
pass
fake_client = FakeSmsClient()
# fake_client.init_app(notify_api)
return fake_client