add v2 event type schema and updates endpoints#25
Conversation
Adds _v2_url() helper to both ERClient and AsyncERClient, which constructs URLs against the v2.0 API root by swapping the version segment in service_root. New methods on both clients: - get_event_type_schema(value, pre_render) -- single event type schema - get_event_type_updates(value) -- revision history for an event type - get_event_type_schemas(pre_render) -- bulk schema list Also teaches AsyncERClient._call() to skip _er_url() when the path is already an absolute URL, enabling the v2 methods to pass full URLs. ERA-12658 Co-authored-by: Cursor <cursoragent@cursor.com>
Replace the brittle `_v2_url()` regex-based v2 URL construction with the cleaner `_api_root(version)` + `base_url` parameter pattern from PR #23. This adds `_api_root()`, updates `_er_url()` to accept a `base_url` param, and threads `base_url` through `_get`, `_post`, `_patch`, and `_call` on both sync and async clients. Reverts the `path.startswith('http')` guard in async `_call()` in favor of the `base_url` approach which is explicit and non-magical. Co-authored-by: Cursor <cursoragent@cursor.com>
V2 URL Convention AlignmentReplaced the Changes:
Tests are unchanged since the resulting URLs are identical. This PR is now compatible with PR #23's infrastructure and will merge cleanly once #23 lands. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for three new v2 API endpoints related to event type schemas and updates. The implementation introduces a new _api_root() helper method in both sync and async clients to construct URLs against different API versions, and adds methods to fetch event type schemas (single and bulk) and revision history.
Changes:
- Adds
_api_root()helper to construct versioned API URLs (v1.0, v2.0, etc.) - Implements three new methods:
get_event_type_schema(),get_event_type_updates(), andget_event_type_schemas()in both sync and async clients - Updates
_er_url(),_get(),_post(),_patch(), and_call()methods to accept optionalbase_urlparameter for API versioning - Adds comprehensive test coverage (8 tests) for async client implementations
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| erclient/client.py | Adds _api_root() helper and three new v2 API methods to both ERClient and AsyncERClient classes; updates internal HTTP methods to support custom base URLs |
| tests/async_client/test_get_event_type_schema.py | Comprehensive test suite (8 tests) covering success, error, parameter, and timeout scenarios for the new async client methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def get_event_type_schema(self, event_type_value, pre_render=False): | ||
| """ | ||
| Get the schema for a single event type (v2 API). | ||
|
|
||
| :param event_type_value: The event type 'value' identifier (e.g. 'rainfall_rep') | ||
| :param pre_render: If True, return the pre-rendered schema | ||
| """ | ||
| return self._get( | ||
| f'eventtypes/{event_type_value}/schema', | ||
| base_url=self._api_root('v2.0'), | ||
| params={'pre_render': pre_render}, | ||
| ) | ||
|
|
||
| def get_event_type_updates(self, event_type_value): | ||
| """ | ||
| Get the revision history for a single event type (v2 API). | ||
|
|
||
| :param event_type_value: The event type 'value' identifier | ||
| """ | ||
| return self._get( | ||
| f'eventtypes/{event_type_value}/updates', | ||
| base_url=self._api_root('v2.0'), | ||
| ) | ||
|
|
||
| def get_event_type_schemas(self, pre_render=False): | ||
| """ | ||
| Get schemas for all event types in bulk (v2 API). | ||
|
|
||
| :param pre_render: If True, return pre-rendered schemas | ||
| """ | ||
| return self._get( | ||
| 'eventtypes/schemas', | ||
| base_url=self._api_root('v2.0'), | ||
| params={'pre_render': pre_render}, | ||
| ) |
There was a problem hiding this comment.
The new sync client methods get_event_type_schema, get_event_type_updates, and get_event_type_schemas lack test coverage. While there are 8 comprehensive tests for the async versions of these methods, there are no corresponding tests for the sync client. The repository shows a pattern of comprehensive testing for the async client but lacks tests for the sync client entirely. Consider adding test coverage for the sync client methods to match the async client test coverage.
| import re | ||
|
|
There was a problem hiding this comment.
The re module is imported but never used in this test file. Consider removing this unused import.
| import re |
| return_value=httpx.Response(httpx.codes.OK, json={"data": schema_response}) | ||
| ) | ||
| result = await er_client.get_event_type_schema("rainfall_rep", pre_render=True) | ||
| assert route.called |
There was a problem hiding this comment.
Variable result is not used.
| assert route.called | |
| assert route.called | |
| assert result == schema_response |
| route = respx_mock.get("/eventtypes/schemas").mock( | ||
| return_value=httpx.Response(httpx.codes.OK, json=schemas_bulk_response) | ||
| ) | ||
| result = await er_client.get_event_type_schemas(pre_render=True) |
There was a problem hiding this comment.
Variable result is not used.
| result = await er_client.get_event_type_schemas(pre_render=True) | |
| await er_client.get_event_type_schemas(pre_render=True) |
Co-authored-by: Cursor <cursoragent@cursor.com>
| def get_event_type_schema(self, event_type_value, pre_render=False): | ||
| """ | ||
| Get the schema for a single event type (v2 API). | ||
|
|
||
| :param event_type_value: The event type 'value' identifier (e.g. 'rainfall_rep') | ||
| :param pre_render: If True, return the pre-rendered schema | ||
| """ | ||
| return self._get( | ||
| f'eventtypes/{event_type_value}/schema', | ||
| base_url=self._api_root('v2.0'), | ||
| params={'pre_render': pre_render}, | ||
| ) | ||
|
|
||
| def get_event_type_updates(self, event_type_value): | ||
| """ | ||
| Get the revision history for a single event type (v2 API). | ||
|
|
||
| :param event_type_value: The event type 'value' identifier | ||
| """ | ||
| return self._get( | ||
| f'eventtypes/{event_type_value}/updates', | ||
| base_url=self._api_root('v2.0'), | ||
| ) | ||
|
|
||
| def get_event_type_schemas(self, pre_render=False): | ||
| """ | ||
| Get schemas for all event types in bulk (v2 API). | ||
|
|
||
| :param pre_render: If True, return pre-rendered schemas | ||
| """ | ||
| return self._get( | ||
| 'eventtypes/schemas', | ||
| base_url=self._api_root('v2.0'), | ||
| params={'pre_render': pre_render}, | ||
| ) |
There was a problem hiding this comment.
Is this indicative of v1 EOL?
And you might want to use the VERSION_2_0 constant for these.
Summary
_v2_url()helper to bothERClientandAsyncERClientthat constructs URLs against the v2.0 API rootget_event_type_schema(value, pre_render=False)-- single event type schema viaeventtypes/{value}/schemaget_event_type_updates(value)-- revision history viaeventtypes/{value}/updatesget_event_type_schemas(pre_render=False)-- bulk schema list viaeventtypes/schemasAsyncERClient._call()to skip_er_url()when the path is already an absolute URLTest plan
Resolves ERA-12658