-
Notifications
You must be signed in to change notification settings - Fork 13
Extend alerting email to managers #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import io | ||
| from unittest import mock | ||
|
|
||
| from unittest.mock import Mock, patch | ||
|
|
||
|
|
@@ -21,6 +22,18 @@ | |
| test-allocation-2,OpenStack CPU,0.25 | ||
| """ | ||
|
|
||
| OUTPUT_EMAIL_TEMPLATE = """Dear New England Research Cloud user, | ||
|
|
||
| Your FakeProd OpenStack Allocation in project FakeProject has reached your preset Alert value. | ||
|
|
||
| - As of midnight last night, your Allocation reached or exceeded your preset Alert value of 100. | ||
| - To view your Allocation information visit http://localhost/allocation/{allocation_id} | ||
|
|
||
| Thank you, | ||
| New England Research Cloud (NERC) | ||
| https://nerc.mghpcc.org/ | ||
| """ | ||
|
|
||
|
|
||
| class TestFetchDailyBillableUsage(base.TestBase): | ||
| def test_get_daily_location_for_prefix(self): | ||
|
|
@@ -107,10 +120,6 @@ def test_get_allocations_for_daily_billing(self): | |
| self.assertNotIn(prod_allocation_3, returned_allocation_ids) | ||
| self.assertNotIn(dev_allocation_1, returned_allocation_ids) | ||
|
|
||
| @patch( | ||
| "coldfront_plugin_cloud.management.commands.fetch_daily_billable_usage.EMAIL_ENABLED", | ||
| True, | ||
| ) | ||
| @patch( | ||
| "coldfront_plugin_cloud.management.commands.fetch_daily_billable_usage.RESOURCES_DAILY_ENABLED", | ||
| ["FakeProd"], | ||
|
|
@@ -179,7 +188,7 @@ def test_call_command(self, mock_get_allocation_usage): | |
| "coldfront_plugin_cloud.management.commands.fetch_daily_billable_usage.Command.send_alert_email" | ||
| ) as mock: | ||
| call_command("fetch_daily_billable_usage", date="2025-11-16") | ||
| mock.assert_called_once_with(allocation_1, fakeprod.name, 200) | ||
| mock.assert_called_once_with(allocation_1, fakeprod, 200) | ||
| self.assertEqual( | ||
| allocation_1.get_attribute(attributes.ALLOCATION_CUMULATIVE_CHARGES), | ||
| "2025-11-16: 225.00 USD", | ||
|
|
@@ -192,3 +201,40 @@ def test_call_command(self, mock_get_allocation_usage): | |
| allocation_1.get_attribute(attributes.ALLOCATION_CUMULATIVE_CHARGES), | ||
| "2025-11-16: 225.00 USD", | ||
| ) | ||
|
|
||
| @patch( | ||
| "coldfront_plugin_cloud.management.commands.fetch_daily_billable_usage.CENTER_BASE_URL", | ||
| "http://localhost", | ||
| ) | ||
| @patch( | ||
| "coldfront_plugin_cloud.management.commands.fetch_daily_billable_usage.EMAIL_SENDER", | ||
| "[email protected]", | ||
| ) | ||
| def test_send_alert_email(self): | ||
| fakeprod = self.new_openstack_resource( | ||
| name="FakeProd", internal_name="FakeProd" | ||
| ) | ||
| prod_project = self.new_project(title="FakeProject") | ||
| allocation_1 = self.new_allocation( | ||
| project=prod_project, resource=fakeprod, quantity=1, status="Active" | ||
| ) | ||
|
|
||
| manager = self.new_user() | ||
| self.new_project_user(manager, prod_project, role="Manager") | ||
|
|
||
| normal_user = self.new_user() | ||
| self.new_project_user(normal_user, prod_project, role="User") | ||
|
|
||
| with mock.patch("coldfront.core.utils.mail.send_email") as mock_send_email: | ||
| Command.send_alert_email( | ||
| allocation=allocation_1, resource=fakeprod, alert_value=100 | ||
| ) | ||
| mock_send_email.assert_called_once_with( | ||
| subject="Allocation Usage Alert", | ||
| body=OUTPUT_EMAIL_TEMPLATE.format( | ||
| allocation_id=allocation_1.id, | ||
| ), | ||
| sender="[email protected]", | ||
| receiver_list=[allocation_1.project.pi.email], | ||
| cc=[manager.email], | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.