notify-api-412 use black to enforce python coding style

This commit is contained in:
Kenneth Kehl
2023-08-25 09:12:23 -07:00
parent c6eb007386
commit 8c9721d8e2
201 changed files with 31660 additions and 28105 deletions

View File

@@ -8,7 +8,6 @@ from app.notify_client.service_api_client import service_api_client
class Event(ABC):
def __init__(
self,
item,
@@ -17,8 +16,8 @@ class Event(ABC):
value_to=None,
):
self.item = item
self.time = item['updated_at'] or item['created_at']
self.user_id = item['created_by_id']
self.time = item["updated_at"] or item["created_at"]
self.user_id = item["created_by_id"]
self.key = key
self.value_from = value_from
self.value_to = value_to
@@ -34,17 +33,13 @@ class Event(ABC):
class ServiceCreationEvent(Event):
relevant = True
def __str__(self):
return 'Created this service and called it {}'.format(
self.item['name']
)
return "Created this service and called it {}".format(self.item["name"])
class ServiceEvent(Event):
@property
def relevant(self):
return self.value_from != self.value_to and bool(self._formatter)
@@ -54,44 +49,38 @@ class ServiceEvent(Event):
@property
def _formatter(self):
return getattr(self, 'format_{}'.format(self.key), None)
return getattr(self, "format_{}".format(self.key), None)
def format_restricted(self):
if self.value_to is False:
return 'Made this service live'
return "Made this service live"
if self.value_to is True:
return 'Put this service back into trial mode'
return "Put this service back into trial mode"
def format_active(self):
if self.value_to is False:
return 'Deleted this service'
return "Deleted this service"
if self.value_to is True:
return 'Unsuspended this service'
return "Unsuspended this service"
def format_contact_link(self):
return 'Set the contact details for this service to {}'.format(
self.value_to
)
return "Set the contact details for this service to {}".format(self.value_to)
def format_email_branding(self):
return 'Updated this services email branding'
return "Updated this services email branding"
def format_inbound_api(self):
return 'Updated the callback for received text messages'
return "Updated the callback for received text messages"
def format_message_limit(self):
return (
'{} this services daily message limit from {} to {}'
).format(
'Reduced' if self.value_from > self.value_to else 'Increased',
return ("{} this services daily message limit from {} to {}").format(
"Reduced" if self.value_from > self.value_to else "Increased",
format_thousands(self.value_from),
format_thousands(self.value_to),
)
def format_name(self):
return (
'Renamed this service from {} to {}'
).format(
return ("Renamed this service from {} to {}").format(
self.value_from, self.value_to
)
@@ -99,61 +88,54 @@ class ServiceEvent(Event):
added = list(sorted(set(self.value_to) - set(self.value_from)))
removed = list(sorted(set(self.value_from) - set(self.value_to)))
if removed and added:
return 'Removed {} from this services permissions, added {}'.format(
return "Removed {} from this services permissions, added {}".format(
formatted_list(removed),
formatted_list(added),
)
if added:
return 'Added {} to this services permissions'.format(
return "Added {} to this services permissions".format(
formatted_list(added)
)
if removed:
return 'Removed {} from this services permissions'.format(
return "Removed {} from this services permissions".format(
formatted_list(removed)
)
def format_prefix_sms(self):
if self.value_to is True:
return 'Set text messages to start with the name of this service'
return "Set text messages to start with the name of this service"
else:
return 'Set text messages to not start with the name of this service'
return "Set text messages to not start with the name of this service"
def format_research_mode(self):
if self.value_to is True:
return 'Put this service into research mode'
return "Put this service into research mode"
else:
return 'Took this service out of research mode'
return "Took this service out of research mode"
def format_service_callback_api(self):
return 'Updated the callback for delivery receipts'
return "Updated the callback for delivery receipts"
def format_go_live_user(self):
return 'Requested for this service to go live'
return "Requested for this service to go live"
class APIKeyEvent(Event):
relevant = True
def __str__(self):
if self.item['updated_at']:
return (
'Revoked the {} API key'
).format(self.item['name'])
if self.item["updated_at"]:
return ("Revoked the {} API key").format(self.item["name"])
else:
return (
'Created an API key called {}'
).format(self.item['name'])
return ("Created an API key called {}").format(self.item["name"])
class APIKeyEvents(ModelList):
model = APIKeyEvent
client_method = service_api_client.get_service_api_key_history
class ServiceEvents(ModelList):
client_method = service_api_client.get_service_service_history
@property
@@ -162,10 +144,9 @@ class ServiceEvents(ModelList):
@staticmethod
def splat(events):
for index, item in enumerate(sorted(
events,
key=lambda event: event['updated_at'] or event['created_at']
)):
for index, item in enumerate(
sorted(events, key=lambda event: event["updated_at"] or event["created_at"])
):
if index == 0:
yield ServiceCreationEvent(item)
else:
@@ -179,5 +160,7 @@ class ServiceEvents(ModelList):
def __init__(self, service_id):
self.items = [
event for event in self.splat(self.client_method(service_id)) if event.relevant
event
for event in self.splat(self.client_method(service_id))
if event.relevant
]