Skip to content

refactor: modernize SDK with idiomatic patterns, structured exceptions, and expanded tests#57

Merged
LegendEvent merged 1 commit intodevfrom
improvements
Apr 14, 2026
Merged

refactor: modernize SDK with idiomatic patterns, structured exceptions, and expanded tests#57
LegendEvent merged 1 commit intodevfrom
improvements

Conversation

@LegendEvent
Copy link
Copy Markdown
Owner

Summary

Comprehensive SDK modernization covering all 27 endpoint modules, error handling, CI, and test coverage — while maintaining full backward compatibility (no public API signature changes).

Changes

Idiomatic Endpoint Migration (all 27 modules)

  • Migrated all endpoint modules from manual _get_headers() + _make_request() calls to idiomatic BaseEndpoint helpers: _get(), _post_json(), _post_form(), _delete()
  • Reduces boilerplate across every dt_*.py file and ensures consistent request handling

Structured Exception Hierarchy

  • New darktrace/exceptions.py with 8 purpose-built exception classes (BadRequestError, AuthenticationError, ForbiddenError, NotFoundError, RateLimitError, ServerError, ConnectionError, base DarktraceError) wrapping requests.HTTPError
  • BaseEndpoint._raise_for_status() maps HTTP status codes to specific exceptions for cleaner error handling by SDK consumers

CI Improvements

  • Expanded Python version matrix: 3.8 → 3.12 (from 3.8-only) in lint workflow

Test Coverage

  • tests/test_auth.py — 28 HMAC signature generation tests
  • tests/test_post_delete.py — 47 POST/DELETE mock tests
  • Updated tests/test_mock.py for new patterns
  • 168 tests pass, 3 skipped (async placeholders)

Cleanup

  • Removed legacy setup.pypyproject.toml is now the sole build configuration
  • Fixed README: removed false "Async-Ready" claim, added exceptions documentation

Test plan

  • pytest tests/ — 168 passed, 3 skipped, 0 failed
  • ruff check . — clean
  • ruff format --check . — clean
  • Full backward compatibility verified — no public method signature changes
  • All 4 Final Verification reviewers (plan compliance, code quality, manual QA, scope fidelity) APPROVED

…s, and expanded tests

- Migrate all 27 endpoint modules to use idiomatic BaseEndpoint helpers
  (_get, _post_json, _post_form, _delete) instead of manual header/request calls
- Add structured exception hierarchy (darktrace/exceptions.py) with 8
  purpose-built HTTP error classes wrapping requests.HTTPError
- Add _raise_for_status() to BaseEndpoint for consistent error handling
- Expand CI matrix to Python 3.8-3.12 in lint workflow
- Add 28 HMAC signature tests (tests/test_auth.py)
- Add 47 POST/DELETE mock tests (tests/test_post_delete.py)
- Remove legacy setup.py (pyproject.toml is sole build config)
- Fix README: remove false async-ready claim, add exceptions docs
- Full backward compatibility maintained: no public API signature changes
@LegendEvent LegendEvent merged commit a41b7bc into dev Apr 14, 2026
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.

1 participant