Skip to content

ERA-12674: Add alert rules and notification method CRUD#36

Open
JoshuaVulcan wants to merge 6 commits intomainfrom
ERA-12674/alerts-notifications
Open

ERA-12674: Add alert rules and notification method CRUD#36
JoshuaVulcan wants to merge 6 commits intomainfrom
ERA-12674/alerts-notifications

Conversation

@JoshuaVulcan
Copy link
Contributor

@JoshuaVulcan JoshuaVulcan commented Feb 11, 2026

Summary

  • Adds full CRUD operations for alert rules and notification methods to both ERClient (sync) and AsyncERClient (async) classes
  • Adds async _delete helper method that properly handles HTTP 204 No Content responses (avoids JSON parsing on empty DELETE response bodies)
  • Comprehensive test coverage for both sync and async clients covering success, error (404, 403, 401), timeout, and empty response scenarios

Endpoints Covered

Endpoint Methods
activity/alerts GET (list), POST (create)
activity/alert/{id} GET, PATCH, DELETE
activity/alerts/conditions GET (list)
activity/notificationmethods GET (list), POST (create)
activity/notificationmethod/{id} GET, PATCH, DELETE

Test Plan

  • All 199 tests pass (pytest tests/ -v)
  • Async alert CRUD tests (success, unauthorized, not found, forbidden, timeout)
  • Async notification method CRUD tests (success, not found, forbidden, timeout)
  • Sync alert CRUD tests (success, not found, forbidden, empty)
  • Sync notification method CRUD tests (success, not found, forbidden, empty)
  • DELETE operations correctly return True without JSON parsing

Resolves ERA-12674

@JoshuaVulcan JoshuaVulcan added autoreviewing PR is currently being auto-reviewed and removed autoreviewing PR is currently being auto-reviewed labels Feb 11, 2026
JoshuaVulcan and others added 2 commits February 11, 2026 10:18
…lients

Implements full CRUD operations for alert rules and notification methods:

Sync ERClient methods:
- get_alerts, get_alert, post_alert, patch_alert, delete_alert
- get_alert_conditions
- get_notification_methods, get_notification_method
- post_notification_method, patch_notification_method, delete_notification_method

Async ERClient methods:
- Same set of async methods for AsyncERClient
- Adds async _delete helper that properly handles 204 No Content responses
  (avoids JSON parsing on empty DELETE responses)

Endpoints covered:
- activity/alerts (list/create)
- activity/alert/{id} (get/patch/delete)
- activity/alerts/conditions (list)
- activity/notificationmethods (list/create)
- activity/notificationmethod/{id} (get/patch/delete)

Test coverage:
- Comprehensive async tests using respx for all alert and notification methods
- Comprehensive sync tests using unittest.mock for all alert and notification methods
- Success, not found, forbidden, unauthorized, timeout, and empty response cases

ERA-12674

Co-authored-by: Cursor <cursoragent@cursor.com>
…st modules

The test_alerts_notifications.py files were duplicates of the more thorough
test_alerts.py and test_notification_methods.py files which provide better
coverage with additional error cases and edge cases.

Co-authored-by: Cursor <cursoragent@cursor.com>
@JoshuaVulcan JoshuaVulcan requested a review from a team as a code owner February 12, 2026 01:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds full CRUD operations for alert rules and notification methods to both the synchronous ERClient and asynchronous AsyncERClient classes, along with comprehensive test coverage for both clients.

Changes:

  • Adds get_alerts, get_alert, post_alert, patch_alert, delete_alert, get_alert_conditions, get_notification_methods, get_notification_method, post_notification_method, patch_notification_method, and delete_notification_method methods to both ERClient and AsyncERClient
  • Adds get_alert_conditions with optional event_type and only_common_factors query parameters
  • Adds comprehensive sync and async test coverage for all new endpoints including success, error, and edge case scenarios

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
erclient/client.py Adds alert rule, alert condition, and notification method CRUD methods to both ERClient (sync) and AsyncERClient (async) classes
tests/sync_client/test_alerts.py Sync client tests for alert rule CRUD and alert conditions
tests/sync_client/test_notification_methods.py Sync client tests for notification method CRUD
tests/async_client/test_alerts.py Async client tests for alert rule CRUD and alert conditions
tests/async_client/test_notification_methods.py Async client tests for notification method CRUD

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +7 to +27


ALERT_ID = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"


def _mock_response(status_code, json_data=None, ok=None, text=None):
"""Create a mock requests.Response."""
mock_resp = MagicMock()
mock_resp.status_code = status_code
if ok is None:
mock_resp.ok = 200 <= status_code < 300
else:
mock_resp.ok = ok
if json_data is not None:
mock_resp.text = json.dumps(json_data)
mock_resp.json.return_value = json_data
elif text is not None:
mock_resp.text = text
else:
mock_resp.text = "{}"
return mock_resp
from erclient import (ERClientBadCredentials, ERClientBadRequest,
ERClientException, ERClientInternalError,
ERClientNotFound, ERClientPermissionDenied,
ERClientRateLimitExceeded, ERClientServiceUnreachable)
Comment on lines +1119 to +1121
if kwargs.get('event_type'):
params['event_type'] = kwargs['event_type']
if kwargs.get('only_common_factors'):
Comment on lines +1549 to +1551
if kwargs.get('event_type'):
params['event_type'] = kwargs['event_type']
if kwargs.get('only_common_factors'):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants