From 76dbe09278ec604017b91d7076bcab2d15b7ab2e Mon Sep 17 00:00:00 2001 From: Philippe Caron Date: Tue, 3 Dec 2024 15:33:21 +0000 Subject: [PATCH 1/3] add new go-live daat to freshdesk integration --- app/clients/freshdesk.py | 2 ++ app/user/contact_request.py | 6 ++++++ tests/app/clients/test_freshdesk.py | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/app/clients/freshdesk.py b/app/clients/freshdesk.py index 785096af5a..6b6e7da162 100644 --- a/app/clients/freshdesk.py +++ b/app/clients/freshdesk.py @@ -49,6 +49,8 @@ def _generate_description(self): f"- Purpose: {self.contact.main_use_case}", f"- Notification types: {self.contact.notification_types}", f"- Expected monthly volume: {self.contact.expected_volume}", + f"- Expected email volumes: Daily {self.contact.daily_email_volume} {f'({self.contact.how_many_more_email})' if self.contact.how_many_more_email else ''} / Yearly {self.contact.annual_email_volume}", + f"- Expected SMS volumes: Daily {self.contact.daily_sms_volume} {f'({self.contact.how_many_more_sms})' if self.contact.how_many_more_sms else ''} / Yearly {self.contact.annual_sms_volume}", "---", self.contact.service_url, ] diff --git a/app/user/contact_request.py b/app/user/contact_request.py index 3473db150a..24970b1844 100644 --- a/app/user/contact_request.py +++ b/app/user/contact_request.py @@ -30,6 +30,12 @@ class ContactRequest: service_url: str = field(default="") notification_types: str = field(default="") expected_volume: str = field(default="") + daily_email_volume: str = field(default="") + annual_email_volume: str = field(default="") + daily_sms_volume: str = field(default="") + annual_sms_volume: str = field(default="") + how_many_more_email: str = field(default="") + how_many_more_sms: str = field(default="") branding_url: str = field(default="") branding_logo_name: str = field(default="") alt_text_en: str = field(default="") diff --git a/tests/app/clients/test_freshdesk.py b/tests/app/clients/test_freshdesk.py index ae0ada8b7e..360a94864d 100644 --- a/tests/app/clients/test_freshdesk.py +++ b/tests/app/clients/test_freshdesk.py @@ -79,6 +79,8 @@ def match_json(request): "- Purpose: main_use_case
" "- Notification types: email, sms
" "- Expected monthly volume: 100k+
" + "- Expected email volumes: Daily more_email (100001) / Yearly within_limit" + "- Expected SMS volumes: Daily 0 / Yearly 0" "---
" "http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92", "email": "test@email.com", @@ -89,6 +91,7 @@ def match_json(request): encoded_auth = base64.b64encode(b"freshdesk-api-key:x").decode("ascii") json_matches = request.json() == expected + print(expected, request.json()) basic_auth_header = request.headers.get("Authorization") == f"Basic {encoded_auth}" return json_matches and basic_auth_header @@ -113,6 +116,12 @@ def match_json(request): "service_url": "http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92", "notification_types": "email, sms", "expected_volume": "100k+", + "daily_email_volume": "more_email", + "annual_email_volume": "within-limit", + "daily_sms_volume": "0", + "annual_sms_volume": "0", + "how_many_more_email": 100001, + "how_many_more_sms": None, } with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() From 27409c905c7b796d7b305804113dae4b4f3db2a1 Mon Sep 17 00:00:00 2001 From: Philippe Caron Date: Wed, 18 Dec 2024 19:19:18 +0000 Subject: [PATCH 2/3] Format tcket description and fix tests --- app/clients/freshdesk.py | 20 ++++++++++++++++---- tests/app/clients/test_freshdesk.py | 27 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/clients/freshdesk.py b/app/clients/freshdesk.py index 6b6e7da162..791bd823e4 100644 --- a/app/clients/freshdesk.py +++ b/app/clients/freshdesk.py @@ -40,6 +40,14 @@ def _generate_description(self): # the ">" character breaks rendering for the freshdesk preview in slack if self.contact.department_org_name: self.contact.department_org_name = self.contact.department_org_name.replace(">", "/") + # Add custom limit only if requested + daily_email_volume = f"{self.contact.daily_email_volume}" + daily_sms_volume = f"{self.contact.daily_sms_volume}" + if self.contact.how_many_more_sms: + daily_email_volume += f" ({self.contact.how_many_more_email})" + if self.contact.how_many_more_sms: + daily_sms_volume += f" ({self.contact.how_many_more_sms})" + message = "
".join( [ f"{self.contact.service_name} just requested to go live.", @@ -47,10 +55,14 @@ def _generate_description(self): f"- Department/org: {self.contact.department_org_name}", f"- Intended recipients: {self.contact.intended_recipients}", f"- Purpose: {self.contact.main_use_case}", - f"- Notification types: {self.contact.notification_types}", - f"- Expected monthly volume: {self.contact.expected_volume}", - f"- Expected email volumes: Daily {self.contact.daily_email_volume} {f'({self.contact.how_many_more_email})' if self.contact.how_many_more_email else ''} / Yearly {self.contact.annual_email_volume}", - f"- Expected SMS volumes: Daily {self.contact.daily_sms_volume} {f'({self.contact.how_many_more_sms})' if self.contact.how_many_more_sms else ''} / Yearly {self.contact.annual_sms_volume}", + "", + "- Expected email volumes:", + f"- Daily: {daily_email_volume}", + f"- Yearly: {self.contact.annual_email_volume}", + "", + "- Expected SMS volumes:", + f"- Daily: {daily_sms_volume}", + f"- Yearly: {self.contact.annual_sms_volume}", "---", self.contact.service_url, ] diff --git a/tests/app/clients/test_freshdesk.py b/tests/app/clients/test_freshdesk.py index 360a94864d..1010a59042 100644 --- a/tests/app/clients/test_freshdesk.py +++ b/tests/app/clients/test_freshdesk.py @@ -73,14 +73,19 @@ def match_json(request): expected = { "product_id": 42, "subject": "Support Request", - "description": "t6 just requested to go live.

" + "description": "t6 just requested to go live.
" + "
" "- Department/org: department_org_name
" "- Intended recipients: internal, external, public
" "- Purpose: main_use_case
" - "- Notification types: email, sms
" - "- Expected monthly volume: 100k+
" - "- Expected email volumes: Daily more_email (100001) / Yearly within_limit" - "- Expected SMS volumes: Daily 0 / Yearly 0" + "
" + "- Expected email volumes:
" + "- Daily: above_limit (None)
" + "- Yearly: within_limit
" + "
" + "- Expected SMS volumes:
" + "- Daily: more_sms (54321)
" + "- Yearly: above_limit
" "---
" "http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92", "email": "test@email.com", @@ -116,12 +121,12 @@ def match_json(request): "service_url": "http://localhost:6012/services/8624bd36-b70b-4d4b-a459-13e1f4770b92", "notification_types": "email, sms", "expected_volume": "100k+", - "daily_email_volume": "more_email", - "annual_email_volume": "within-limit", - "daily_sms_volume": "0", - "annual_sms_volume": "0", - "how_many_more_email": 100001, - "how_many_more_sms": None, + "daily_email_volume": "above_limit", + "annual_email_volume": "within_limit", + "daily_sms_volume": "more_sms", + "annual_sms_volume": "above_limit", + "how_many_more_email": None, + "how_many_more_sms": 54321, } with notify_api.app_context(): response = freshdesk.Freshdesk(ContactRequest(**data)).send_ticket() From 9bf7ad99061714f6c86eb2c9db5f4b50a7d859ca Mon Sep 17 00:00:00 2001 From: Philippe Caron Date: Wed, 18 Dec 2024 19:59:23 +0000 Subject: [PATCH 3/3] remove print line --- tests/app/clients/test_freshdesk.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/app/clients/test_freshdesk.py b/tests/app/clients/test_freshdesk.py index 1010a59042..36002aca9b 100644 --- a/tests/app/clients/test_freshdesk.py +++ b/tests/app/clients/test_freshdesk.py @@ -96,7 +96,6 @@ def match_json(request): encoded_auth = base64.b64encode(b"freshdesk-api-key:x").decode("ascii") json_matches = request.json() == expected - print(expected, request.json()) basic_auth_header = request.headers.get("Authorization") == f"Basic {encoded_auth}" return json_matches and basic_auth_header