-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add logic to API usage notification templates (#4206)
- Loading branch information
Showing
5 changed files
with
74 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
api/organisations/templates/organisations/api_usage_notification_limit.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,6 +293,7 @@ def test_handle_api_usage_notifications_below_100( | |
# Given | ||
now = timezone.now() | ||
organisation.subscription.plan = SCALE_UP | ||
organisation.subscription.subscription_id = "fancy_id" | ||
organisation.subscription.save() | ||
OrganisationSubscriptionInformationCache.objects.create( | ||
organisation=organisation, | ||
|
@@ -328,7 +329,9 @@ def test_handle_api_usage_notifications_below_100( | |
assert email.body == ( | ||
"Hi there,\n\nThe API usage for Test Org has reached " | ||
"90% within the current subscription period. Please " | ||
"consider upgrading your organisation's account limits.\n\n" | ||
"consider upgrading your organisation's account limits.\n\n\n" | ||
"Please note that once the 100% use has been breached " | ||
"automated charges for your account may apply.\n\n" | ||
"Thank you!\n\nThe Flagsmith Team\n" | ||
) | ||
|
||
|
@@ -337,16 +340,18 @@ def test_handle_api_usage_notifications_below_100( | |
assert email.alternatives[0][1] == "text/html" | ||
|
||
assert email.alternatives[0][0] == ( | ||
"<table>\n\n <tr>\n\n " | ||
"<td>Hi there,</td>\n\n </tr>\n\n " | ||
"<tr>\n\n <td>\n " | ||
"The API usage for Test Org has reached\n " | ||
"90% within the current subscription period.\n " | ||
"Please consider upgrading your organisation's account limits.\n" | ||
" </td>\n\n\n </tr>\n\n " | ||
"<tr>\n\n <td>Thank you!</td>\n\n " | ||
" </tr>\n\n <tr>\n\n " | ||
"<td>The Flagsmith Team</td>\n\n " | ||
"<table>\n\n <tr>\n\n <td>Hi " | ||
"there,</td>\n\n </tr>\n\n <tr>\n\n " | ||
" <td>\n The API usage for Test " | ||
"Org has reached\n 90% within the current " | ||
"subscription period.\n Please consider " | ||
"upgrading your organisation's account limits.\n " | ||
" \n Please note that once the 100%" | ||
" use has been breached automated charges for your account " | ||
"may apply.\n \n\n </td>\n\n" | ||
"\n </tr>\n\n <tr>\n\n <td>" | ||
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n " | ||
" <td>The Flagsmith Team</td>\n\n " | ||
"</tr>\n\n</table>\n" | ||
) | ||
|
||
|
@@ -387,6 +392,7 @@ def test_handle_api_usage_notifications_above_100( | |
# Given | ||
now = timezone.now() | ||
organisation.subscription.plan = SCALE_UP | ||
organisation.subscription.subscription_id = "fancy_id" | ||
organisation.subscription.save() | ||
OrganisationSubscriptionInformationCache.objects.create( | ||
organisation=organisation, | ||
|
@@ -421,29 +427,27 @@ def test_handle_api_usage_notifications_above_100( | |
email = mailoutbox[0] | ||
assert email.subject == "Flagsmith API use has reached 100%" | ||
assert email.body == ( | ||
"Hi there,\n\nThe API usage for Test Org has breached " | ||
"100% within the current subscription period. Please " | ||
"upgrade your organisation's account to ensure " | ||
"continued service.\n\nThank you!\n\n" | ||
"The Flagsmith Team\n" | ||
"Hi there,\n\nThe API usage for Test Org has breached 100% " | ||
"within the current subscription period.\n\n\nPlease note " | ||
"that automated charges for your account may apply.\n\n\n" | ||
"Thank you!\n\nThe Flagsmith Team\n" | ||
) | ||
|
||
assert len(email.alternatives) == 1 | ||
assert len(email.alternatives[0]) == 2 | ||
assert email.alternatives[0][1] == "text/html" | ||
|
||
assert email.alternatives[0][0] == ( | ||
"<table>\n\n <tr>\n\n <td>Hi " | ||
"there,</td>\n\n </tr>\n\n <tr>\n\n " | ||
" <td>\n The API usage for Test Org " | ||
"has breached\n 100% within the " | ||
"current subscription period.\n " | ||
"Please upgrade your organisation's account to ensure " | ||
"continued service.\n </td>\n\n\n " | ||
" </tr>\n\n <tr>\n\n <td>" | ||
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n" | ||
" <td>The Flagsmith Team</td>\n\n " | ||
"</tr>\n\n</table>\n" | ||
"<table>\n\n <tr>\n\n <td>Hi there," | ||
"</td>\n\n </tr>\n\n <tr>\n\n <td>" | ||
"\n The API usage for Test Org has breached" | ||
"\n 100% within the current subscription period." | ||
"\n \n Please note that " | ||
"automated charges for your account may apply.\n " | ||
"\n </td>\n\n\n </tr>\n\n <tr>" | ||
"\n\n <td>Thank you!</td>\n\n </tr>" | ||
"\n\n <tr>\n\n <td>The Flagsmith " | ||
"Team</td>\n\n </tr>\n\n</table>\n" | ||
) | ||
|
||
assert email.from_email == "[email protected]" | ||
|
@@ -482,7 +486,8 @@ def test_handle_api_usage_notifications_for_free_accounts( | |
mailoutbox: list[EmailMultiAlternatives], | ||
) -> None: | ||
# Given | ||
assert organisation.subscription.is_free_plan | ||
assert organisation.is_paid is False | ||
assert organisation.subscription.is_free_plan is True | ||
assert organisation.subscription.max_api_calls == MAX_API_CALLS_IN_FREE_PLAN | ||
|
||
mock_api_usage = mocker.patch( | ||
|
@@ -510,28 +515,31 @@ def test_handle_api_usage_notifications_for_free_accounts( | |
assert email.subject == "Flagsmith API use has reached 100%" | ||
assert email.body == ( | ||
"Hi there,\n\nThe API usage for Test Org has breached " | ||
"100% within the current subscription period. Please " | ||
"upgrade your organisation's account to ensure " | ||
"continued service.\n\nThank you!\n\n" | ||
"The Flagsmith Team\n" | ||
"100% within the current subscription period.\n\n\nPlease " | ||
"note that the serving of feature flags and admin access " | ||
"may be disabled after a grace period, so please upgrade " | ||
"your organisation's account to ensure continued service." | ||
"\n\n\nThank you!\n\nThe Flagsmith Team\n" | ||
) | ||
|
||
assert len(email.alternatives) == 1 | ||
assert len(email.alternatives[0]) == 2 | ||
assert email.alternatives[0][1] == "text/html" | ||
|
||
assert email.alternatives[0][0] == ( | ||
"<table>\n\n <tr>\n\n <td>Hi " | ||
"there,</td>\n\n </tr>\n\n <tr>\n\n " | ||
" <td>\n The API usage for Test Org " | ||
"has breached\n 100% within the " | ||
"current subscription period.\n " | ||
"Please upgrade your organisation's account to ensure " | ||
"continued service.\n </td>\n\n\n " | ||
" </tr>\n\n <tr>\n\n <td>" | ||
"Thank you!</td>\n\n </tr>\n\n <tr>\n\n" | ||
" <td>The Flagsmith Team</td>\n\n " | ||
"</tr>\n\n</table>\n" | ||
"<table>\n\n <tr>\n\n <td>Hi there," | ||
"</td>\n\n </tr>\n\n <tr>\n\n " | ||
" <td>\n The API usage for Test Org has" | ||
" breached\n 100% within the current " | ||
"subscription period.\n \n " | ||
" Please note that the serving of feature flags and " | ||
"admin access may be disabled after a grace period, so " | ||
"please upgrade your organisation's account to ensure " | ||
"continued service.\n \n " | ||
"</td>\n\n\n </tr>\n\n <tr>\n\n " | ||
" <td>Thank you!</td>\n\n </tr>\n\n " | ||
"<tr>\n\n <td>The Flagsmith Team</td>" | ||
"\n\n </tr>\n\n</table>\n" | ||
) | ||
|
||
assert email.from_email == "[email protected]" | ||
|