From 3ff6d386601620791ebc8aa9639e4a831c70451d Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Fri, 29 Dec 2023 18:11:55 -0500 Subject: [PATCH 1/3] Making the new pinpoint client. Signed-off-by: Cliff Hill --- app/clients/__init__.py | 4 +++- app/clients/email/__init__.py | 5 ++++- app/clients/pinpoint/__init__.py | 0 app/clients/sms/__init__.py | 5 +++++ migrations/versions/0409_fix_service_name.py | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 app/clients/pinpoint/__init__.py diff --git a/app/clients/__init__.py b/app/clients/__init__.py index c6b620517..7ab453318 100644 --- a/app/clients/__init__.py +++ b/app/clients/__init__.py @@ -1,3 +1,5 @@ +from typing import Protocol + from botocore.config import Config AWS_CLIENT_CONFIG = Config( @@ -22,7 +24,7 @@ class ClientException(Exception): pass -class Client(object): +class Client(Protocol): """ Base client for sending notifications. """ diff --git a/app/clients/email/__init__.py b/app/clients/email/__init__.py index 7a2f710a3..1855308b5 100644 --- a/app/clients/email/__init__.py +++ b/app/clients/email/__init__.py @@ -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.") diff --git a/app/clients/pinpoint/__init__.py b/app/clients/pinpoint/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/app/clients/sms/__init__.py b/app/clients/sms/__init__.py index 2e7f27cdc..cd4ca57a7 100644 --- a/app/clients/sms/__init__.py +++ b/app/clients/sms/__init__.py @@ -1,3 +1,5 @@ +from abc import abstractmethod + from app.clients import Client, ClientException @@ -18,11 +20,14 @@ class SmsClient(Client): Base Sms client for sending smss. """ + @abstractmethod 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.") + @abstractmethod def get_name(self): raise NotImplementedError("TODO Need to implement.") diff --git a/migrations/versions/0409_fix_service_name.py b/migrations/versions/0409_fix_service_name.py index 04c6ba359..6c90b65ce 100644 --- a/migrations/versions/0409_fix_service_name.py +++ b/migrations/versions/0409_fix_service_name.py @@ -27,7 +27,8 @@ def upgrade(): # select_by_val = service_id input_params = {"service_id": service_id} conn.execute( - text("update services set name='Notify.gov' where id =:service_id"), input_params + text("update services set name='Notify.gov' where id =:service_id"), + input_params, ) # table_name = 'services_history' From d714ebcd5d13f3fec63a10a3236cf08e61fc4664 Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Thu, 4 Jan 2024 09:00:41 -0500 Subject: [PATCH 2/3] Restructured how clients are implemented. Signed-off-by: Cliff Hill --- app/clients/__init__.py | 5 ++++- .../performance_platform_client.py | 2 +- app/clients/sms/__init__.py | 15 ++++++++------- app/clients/sms/aws_sns.py | 3 --- tests/app/clients/test_sms.py | 6 ++++++ 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/clients/__init__.py b/app/clients/__init__.py index 7ab453318..1946f70e6 100644 --- a/app/clients/__init__.py +++ b/app/clients/__init__.py @@ -1,3 +1,4 @@ +from abc import abstractmethod from typing import Protocol from botocore.config import Config @@ -29,7 +30,9 @@ 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): diff --git a/app/clients/performance_platform/performance_platform_client.py b/app/clients/performance_platform/performance_platform_client.py index 7e3d8c5be..ec0f6b999 100644 --- a/app/clients/performance_platform/performance_platform_client.py +++ b/app/clients/performance_platform/performance_platform_client.py @@ -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") diff --git a/app/clients/sms/__init__.py b/app/clients/sms/__init__.py index cd4ca57a7..97639e970 100644 --- a/app/clients/sms/__init__.py +++ b/app/clients/sms/__init__.py @@ -1,4 +1,5 @@ -from abc import abstractmethod +from abc import abstractmethod, abstractproperty +from typing import final from app.clients import Client, ClientException @@ -20,14 +21,14 @@ class SmsClient(Client): Base Sms client for sending smss. """ - @abstractmethod - 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.") - @abstractmethod - def get_name(self): + @abstractproperty + def name(self): raise NotImplementedError("TODO Need to implement.") + + @final + def get_name(self): + return self.name diff --git a/app/clients/sms/aws_sns.py b/app/clients/sms/aws_sns.py index 1061ec9ce..d75122a7e 100644 --- a/app/clients/sms/aws_sns.py +++ b/app/clients/sms/aws_sns.py @@ -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) diff --git a/tests/app/clients/test_sms.py b/tests/app/clients/test_sms.py index 5718cbc81..f2a5abfed 100644 --- a/tests/app/clients/test_sms.py +++ b/tests/app/clients/test_sms.py @@ -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 From b88d1f0aa25caa4f72bcef13d473aa08d6527061 Mon Sep 17 00:00:00 2001 From: Cliff Hill Date: Thu, 4 Jan 2024 15:07:50 -0500 Subject: [PATCH 3/3] Minor tweaks Signed-off-by: Cliff Hill --- app/clients/pinpoint/__init__.py | 0 app/clients/sms/__init__.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 app/clients/pinpoint/__init__.py diff --git a/app/clients/pinpoint/__init__.py b/app/clients/pinpoint/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/clients/sms/__init__.py b/app/clients/sms/__init__.py index 97639e970..f3a366648 100644 --- a/app/clients/sms/__init__.py +++ b/app/clients/sms/__init__.py @@ -13,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):