Skip to content

MPT-13307: implement exchange currencies resource#274

Merged
albertsola merged 1 commit intomainfrom
MPT-13307/exchange-currencies-resource
Apr 2, 2026
Merged

MPT-13307: implement exchange currencies resource#274
albertsola merged 1 commit intomainfrom
MPT-13307/exchange-currencies-resource

Conversation

@albertsola
Copy link
Copy Markdown
Contributor

@albertsola albertsola commented Apr 2, 2026

Summary

Implements the exchange domain module with full support for the Currency endpoints exposed by the MPT API (/public/v1/exchange/currencies).

Changes

New files

  • mpt_api_client/resources/exchange/currencies.pyCurrency model + CurrenciesService / AsyncCurrenciesService
  • mpt_api_client/resources/exchange/exchange.pyExchange / AsyncExchange module classes
  • mpt_api_client/resources/exchange/__init__.py
  • tests/unit/resources/exchange/test_currencies.py — 31 unit tests

Updated files

  • mpt_api_client/resources/__init__.py — exports Exchange, AsyncExchange
  • mpt_api_client/mpt_client.py — adds .exchange property to MPTClient and AsyncMPTClient
  • pyproject.toml — per-file-ignores for the exchange module

API Coverage

Method Endpoint Operation
GET /public/v1/exchange/currencies iterate()
POST /public/v1/exchange/currencies create(data, file=icon)
GET /public/v1/exchange/currencies/{id} get(id)
PUT /public/v1/exchange/currencies/{id} update(id, data, file=icon)
DELETE /public/v1/exchange/currencies/{id} delete(id)
GET /public/v1/exchange/currencies/{id}/icon download_icon(id)

Testing

  • 31 unit tests covering model fields, mixin presence, all CRUD operations and icon download (sync + async)
  • All 1788 tests pass
  • make check-all clean (ruff, flake8, mypy)

Closes MPT-13307

  • Implements new exchange domain module with full support for Currency endpoints (/public/v1/exchange/currencies)
  • Introduces Currency model with typed fields: name, code, precision, statistics, status, icon, revision, and audit
  • Provides CurrenciesService and AsyncCurrenciesService with sync/async support for list (iterate), create (with icon upload), get, update (with icon upload), delete, and icon download endpoints
  • Adds Exchange and AsyncExchange module classes exposing a currencies property
  • Adds .exchange property to MPTClient and AsyncMPTClient for accessing the exchange resources
  • Exports Exchange and AsyncExchange via mpt_api_client.resources and package mpt_api_client.resources.exchange
  • Adds 31 unit tests covering model serialization, mixin presence, CRUD operations, and icon download for both sync and async variants (all tests pass)
  • Updates lint configuration (pyproject.toml) with per-file-ignores for the exchange module and its tests

@albertsola albertsola requested a review from a team as a code owner April 2, 2026 14:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: aae2876c-a92f-4f18-95bd-0ef6561b3dd8

📥 Commits

Reviewing files that changed from the base of the PR and between b3f1274 and cb368b2.

📒 Files selected for processing (10)
  • mpt_api_client/mpt_client.py
  • mpt_api_client/resources/__init__.py
  • mpt_api_client/resources/exchange/__init__.py
  • mpt_api_client/resources/exchange/currencies.py
  • mpt_api_client/resources/exchange/exchange.py
  • pyproject.toml
  • tests/unit/resources/exchange/__init__.py
  • tests/unit/resources/exchange/test_currencies.py
  • tests/unit/resources/exchange/test_exchange.py
  • tests/unit/test_mpt_client.py
✅ Files skipped from review due to trivial changes (4)
  • pyproject.toml
  • mpt_api_client/resources/init.py
  • tests/unit/resources/exchange/test_exchange.py
  • tests/unit/resources/exchange/test_currencies.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • mpt_api_client/mpt_client.py
  • mpt_api_client/resources/exchange/exchange.py

📝 Walkthrough

Walkthrough

Adds an exchange resource package with a Currency model, sync/async Currencies services (CRUD + icon download), and Exchange/AsyncExchange accessors on both client classes. Updates package exports, lint ignore rules, and adds unit tests for the new resources.

Changes

Cohort / File(s) Summary
Client Extensions
mpt_api_client/mpt_client.py
Added exchange property to AsyncMPTClient and MPTClient, returning AsyncExchange(http_client=...) and Exchange(http_client=...).
Resource Package Exports
mpt_api_client/resources/__init__.py, mpt_api_client/resources/exchange/__init__.py
Exported AsyncExchange and Exchange from the resources package and the new exchange subpackage.
Exchange API Surface
mpt_api_client/resources/exchange/exchange.py
Added Exchange and AsyncExchange classes holding http_client and exposing a currencies property that instantiates the corresponding service.
Currencies Resource
mpt_api_client/resources/exchange/currencies.py
Added Currency model, CurrenciesService and AsyncCurrenciesService, CurrenciesServiceConfig; services support create/get/update/delete/iterate and download_icon (sync + async).
Lint Configuration
pyproject.toml
Added flake8/ruff per-file-ignores for mpt_api_client/resources/exchange/*.py and tests/unit/resources/exchange/*.py.
Unit Tests - Exchange resources
tests/unit/resources/exchange/test_currencies.py, tests/unit/resources/exchange/test_exchange.py
Added tests for Currency model, sync/async services (CRUD, upload, download_icon), and that Exchange/AsyncExchange wire http_client to currencies.
Unit Tests - Client
tests/unit/test_mpt_client.py
Updated existing client tests to include exchange / AsyncExchange in attribute/type assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed PR title contains Jira issue key MPT-13307 in correct MPT-XXXX format at the beginning.
Test Coverage Required ✅ Passed The PR includes comprehensive test coverage with 3 test files modified/created alongside 6 code files and pyproject.toml, ensuring all modifications are accompanied by corresponding tests.
Single Commit Required ✅ Passed The pull request contains exactly one commit (cb368b2: MPT-13307: implement exchange currencies resource), satisfying the requirement for a single commit.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@albertsola albertsola force-pushed the MPT-13307/exchange-currencies-resource branch from b3f1274 to d1d4429 Compare April 2, 2026 14:27
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/unit/resources/exchange/test_currencies.py (1)

85-270: Consider extracting repeated endpoint strings into fixtures/constants.

This would reduce duplication and make future endpoint changes easier to maintain.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/resources/exchange/test_currencies.py` around lines 85 - 270, Many
tests repeat the same hardcoded URLs (e.g.,
"https://api.example.com/public/v1/exchange/currencies/{currency_id}" and the
"/icon" variant) which should be centralized; add a module-level constant (e.g.,
CURRENCIES_BASE = "https://api.example.com/public/v1/exchange/currencies") or a
fixture (e.g., currencies_endpoint(currency_id) and
currency_icon_endpoint(currency_id)) in this test module or conftest, then
update each test (functions like test_get_currency, test_async_get_currency,
test_create_currency, test_update_currency, test_delete_currency,
test_download_icon_returns_file_model, etc.) to use the constant/fixture instead
of embedding the raw string so future URL changes are made in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/unit/resources/exchange/test_currencies.py`:
- Around line 85-270: Many tests repeat the same hardcoded URLs (e.g.,
"https://api.example.com/public/v1/exchange/currencies/{currency_id}" and the
"/icon" variant) which should be centralized; add a module-level constant (e.g.,
CURRENCIES_BASE = "https://api.example.com/public/v1/exchange/currencies") or a
fixture (e.g., currencies_endpoint(currency_id) and
currency_icon_endpoint(currency_id)) in this test module or conftest, then
update each test (functions like test_get_currency, test_async_get_currency,
test_create_currency, test_update_currency, test_delete_currency,
test_download_icon_returns_file_model, etc.) to use the constant/fixture instead
of embedding the raw string so future URL changes are made in one place.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 52f541a9-e019-445b-866b-8796eb3032e7

📥 Commits

Reviewing files that changed from the base of the PR and between 29f9caf and b3f1274.

📒 Files selected for processing (8)
  • mpt_api_client/mpt_client.py
  • mpt_api_client/resources/__init__.py
  • mpt_api_client/resources/exchange/__init__.py
  • mpt_api_client/resources/exchange/currencies.py
  • mpt_api_client/resources/exchange/exchange.py
  • pyproject.toml
  • tests/unit/resources/exchange/__init__.py
  • tests/unit/resources/exchange/test_currencies.py

- Add Currency model with all fields (name, code, precision, statistics,
  status, icon, revision, audit)
- Add CurrenciesService and AsyncCurrenciesService with list, get, create,
  update, delete and download_icon operations
- Add Exchange and AsyncExchange module classes
- Register exchange module on MPTClient and AsyncMPTClient
- Add per-file-ignores for exchange module in pyproject.toml
- Add unit tests following AAA and single-assertion practices

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@albertsola albertsola force-pushed the MPT-13307/exchange-currencies-resource branch from d1d4429 to cb368b2 Compare April 2, 2026 14:30
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2026

@albertsola albertsola merged commit 5340a75 into main Apr 2, 2026
4 checks passed
@albertsola albertsola deleted the MPT-13307/exchange-currencies-resource branch April 2, 2026 15:07
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