Skip to content

Conversation

@robcsegal
Copy link
Contributor

@robcsegal robcsegal commented Dec 10, 2025

Added commerce orders assets endpoints

https://softwareone.atlassian.net/browse/MPT-16319

Summary by CodeRabbit

  • New Features

    • Order assets management: create, retrieve, update, delete assets tied to a specific order via a new assets entry point.
    • Asset template rendering: render and retrieve asset templates for a given order.
    • Synchronous and asynchronous access: asset operations and rendering available in both sync and async flows.
  • Tests

    • Added comprehensive unit tests covering asset operations, endpoint construction, and render behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 10, 2025

Walkthrough

Adds a new OrdersAsset resource: a model and parallel sync/async service implementations, plus assets(order_id) methods on both sync and async OrdersService that return configured asset service instances. Unit tests for service wiring and render behavior were added.

Changes

Cohort / File(s) Summary
Orders service integration
mpt_api_client/resources/commerce/orders.py
Imported AsyncOrdersAssetService and OrdersAssetService. Added assets(self, order_id: str) methods on OrdersService and AsyncOrdersService that construct and return the respective asset service with http_client and endpoint_params={"order_id": order_id}.
New orders asset module
mpt_api_client/resources/commerce/orders_asset.py
New module adding OrdersAsset model, OrdersAssetServiceConfig (_endpoint = "/public/v1/commerce/orders/{order_id}/assets", _collection_key = "data"), OrdersAssetService (sync) and AsyncOrdersAssetService (async). Both services mix in managed-resource and collection behaviors and implement render(resource_id) which requests the render sub-endpoint and returns response.text.
Orders service tests
tests/unit/resources/commerce/test_orders.py
Added imports and tests test_asset_service() and test_async_asset_service() verifying assets() returns correct service types with endpoint_params. (File contains duplicated test blocks for these checks.)
Orders asset module tests
tests/unit/resources/commerce/test_orders_asset.py
New test module with fixtures for sync/async services; parametrized tests assert presence of get/create/update/delete/render, correct endpoint path /public/v1/commerce/orders/ORD-123/assets, and verify render returns mocked response content for both sync and async calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect mixin composition and method resolution for OrdersAssetService / AsyncOrdersAssetService.
  • Verify endpoint_params propagation and endpoint formatting in render() methods.
  • Confirm parity between sync and async implementations.
  • Review duplicated test blocks in tests/unit/resources/commerce/test_orders.py.

Suggested reviewers

  • jentyk
  • svazquezco
  • alephsur
  • ruben-sebrango

Poem

🐇 I hopped through code with a carroted grin,

Added assets and rendering to tuck safely in.
Sync and async both dance in a row,
Orders now shine with a bright asset glow. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding commerce orders assets endpoints. It is concise, specific, and directly relates to the primary objective of the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch MPT-16319-add-missing-commerce-orders-assets-endpoints

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e6f9ff and 8d31267.

📒 Files selected for processing (4)
  • mpt_api_client/resources/commerce/orders.py (3 hunks)
  • mpt_api_client/resources/commerce/orders_asset.py (1 hunks)
  • tests/unit/resources/commerce/test_orders.py (2 hunks)
  • tests/unit/resources/commerce/test_orders_asset.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/resources/commerce/test_orders_asset.py
  • tests/unit/resources/commerce/test_orders.py
🧰 Additional context used
🧬 Code graph analysis (2)
mpt_api_client/resources/commerce/orders.py (2)
mpt_api_client/resources/commerce/orders_asset.py (2)
  • AsyncOrdersAssetService (48-70)
  • OrdersAssetService (23-45)
mpt_api_client/resources/commerce/commerce.py (2)
  • assets (33-35)
  • assets (60-62)
mpt_api_client/resources/commerce/orders_asset.py (5)
mpt_api_client/http/async_service.py (1)
  • AsyncService (12-80)
mpt_api_client/http/service.py (1)
  • Service (12-80)
mpt_api_client/http/mixins.py (2)
  • AsyncCollectionMixin (538-605)
  • CollectionMixin (469-535)
mpt_api_client/models/model.py (1)
  • Model (65-125)
mpt_api_client/http/types.py (1)
  • text (36-38)
🪛 Ruff (0.14.8)
mpt_api_client/resources/commerce/orders_asset.py

23-23: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)


48-48: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
mpt_api_client/resources/commerce/orders_asset.py (2)

11-20: Orders asset model + render endpoints look consistent with existing patterns

OrdersAsset, its config, and both sync/async services follow the same mixin and endpoint conventions as other commerce resources, and the render() methods correctly delegate to _resource_do_request(..., "GET", "render") and return response.text, matching the existing template() behavior on orders. No functional issues spotted here.

Also applies to: 31-45, 56-70


23-23: Remove unused/unknown # noqa: WPS215 directives to satisfy Ruff

Ruff reports RUF100 because WPS215 is unknown/unused on these class definitions. Since the classes are fine as-is, you can just drop the # noqa comments.

-class OrdersAssetService(  # noqa: WPS215
+class OrdersAssetService(
@@
-class AsyncOrdersAssetService(  # noqa: WPS215
+class AsyncOrdersAssetService(

This should clear the lint without affecting behavior.

Also applies to: 48-48

⛔ Skipped due to learnings
Learnt from: jentyk
Repo: softwareone-platform/mpt-api-python-client PR: 136
File: tests/e2e/notifications/subscribers/conftest.py:14-25
Timestamp: 2025-12-01T10:48:52.586Z
Learning: The repository softwareone-platform/mpt-api-python-client uses wemake-python-styleguide linter, so noqa directives for WPS rules should not be flagged as unused.
mpt_api_client/resources/commerce/orders.py (1)

12-15: New assets(order_id) wiring for sync/async orders services is consistent and correct

Importing OrdersAssetService/AsyncOrdersAssetService and exposing assets(order_id) on both OrdersService and AsyncOrdersService mirrors the existing subscriptions() pattern, correctly passing http_client and endpoint_params={"order_id": order_id} so the {order_id} placeholder in the assets endpoint can be resolved. Public API shape and docs look consistent with the rest of the commerce resources.

Also applies to: 122-134, 240-252


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

Warnings
⚠️

Some newly added source files do not have corresponding tests in the tests/ folder with matching structure and the test_ prefix.

✅ Found Jira issue key in the title: MPT-16319

Tests mirroring check (created files only)

Added source file Expected test (added in this PR)
mpt_api_client/resources/commerce/orders_asset.py tests/resources/commerce/test_orders_asset.py

Generated by 🚫 dangerJS against 8d31267

Copy link

@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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/resources/commerce/test_orders_asset.py (1)

49-82: Optionally assert respx route invocation in render tests

The render tests verify returned markdown content, but they don’t assert that the mocked respx.get route was actually hit. You could capture the route into a variable and assert call_count == 1 (similar to other tests) to make the tests more robust against future refactors.

-    with respx.mock:
-        respx.get(
-            "https://api.example.com/public/v1/commerce/orders/ORD-123/assets/ASSET-456/render"
-        ).mock(
+    with respx.mock:
+        mock_route = respx.get(
+            "https://api.example.com/public/v1/commerce/orders/ORD-123/assets/ASSET-456/render"
+        ).mock(
             return_value=httpx.Response(
@@
-        result = asset_service.render("ORD-123", "ASSET-456")
-
-        assert result == template_content
+        result = asset_service.render("ORD-123", "ASSET-456")
+
+        assert mock_route.call_count == 1
+        assert result == template_content

(Same pattern could be applied to test_async_render.)

mpt_api_client/resources/commerce/orders_asset.py (1)

23-28: Clean up unused # noqa: WPS215 directives

Ruff flags these # noqa: WPS215 comments as unknown/unused (RUF100). Unless you still run a separate linter that depends on WPS215, it’s simpler to drop them from both service classes.

-class OrdersAssetService(  # noqa: WPS215
+class OrdersAssetService(
@@
-class AsyncOrdersAssetService(  # noqa: WPS215
+class AsyncOrdersAssetService(

Also applies to: 49-55

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d927ac4 and 36a63cd.

📒 Files selected for processing (4)
  • mpt_api_client/resources/commerce/orders.py (3 hunks)
  • mpt_api_client/resources/commerce/orders_asset.py (1 hunks)
  • tests/unit/resources/commerce/test_orders.py (2 hunks)
  • tests/unit/resources/commerce/test_orders_asset.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
mpt_api_client/resources/commerce/orders_asset.py (4)
mpt_api_client/http/async_service.py (1)
  • AsyncService (12-80)
mpt_api_client/http/service.py (1)
  • Service (12-80)
mpt_api_client/models/model.py (1)
  • Model (65-125)
mpt_api_client/http/types.py (1)
  • text (36-38)
tests/unit/resources/commerce/test_orders_asset.py (4)
mpt_api_client/resources/commerce/orders_asset.py (3)
  • OrdersAssetService (23-46)
  • render (31-46)
  • render (57-72)
tests/unit/conftest.py (2)
  • http_client (17-18)
  • async_http_client (22-23)
mpt_api_client/http/base_service.py (1)
  • path (28-30)
mpt_api_client/http/types.py (1)
  • Response (27-42)
🪛 Ruff (0.14.8)
mpt_api_client/resources/commerce/orders_asset.py

23-23: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)


31-31: Unused method argument: order_id

(ARG002)


49-49: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)


57-57: Unused method argument: order_id

(ARG002)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (8)
mpt_api_client/resources/commerce/orders.py (3)

12-15: Asset service imports wired correctly

Importing AsyncOrdersAssetService and OrdersAssetService here cleanly exposes the new assets functionality for both sync and async order services; placement and usage are consistent with existing subscription imports.


122-134: Sync assets() factory mirrors existing subscriptions() pattern

OrdersService.assets() correctly constructs an OrdersAssetService with http_client and endpoint_params={"order_id": order_id}, matching how subscriptions() scopes child resources to an order.


240-252: Async assets() factory is consistent with sync API

AsyncOrdersService.assets() returns AsyncOrdersAssetService with the expected endpoint_params, giving a symmetric async surface to the sync assets() helper.

tests/unit/resources/commerce/test_orders_asset.py (1)

11-47: Service fixtures and basic capability tests look solid

The fixtures, mixin presence checks, and endpoint path assertions correctly validate that both sync and async asset services are scoped to order_id and expose the expected CRUD+render surface.

tests/unit/resources/commerce/test_orders.py (3)

6-9: Asset service imports align with new Orders API

Importing OrdersAssetService and AsyncOrdersAssetService here matches the new assets() helpers on the orders services; this keeps tests in sync with the production API surface.


251-258: Sync assets() factory test correctly validates wiring

test_asset_service asserts both the returned type and endpoint_params == {"order_id": "ORD-123"}, which is exactly what we want to guarantee from OrdersService.assets().


260-266: Async assets() factory test mirrors the sync coverage

test_async_asset_service provides the same checks for the async variant, ensuring AsyncOrdersService.assets() is wired identically.

mpt_api_client/resources/commerce/orders_asset.py (1)

11-21: Model and service config follow existing resource conventions

OrdersAsset plus OrdersAssetServiceConfig (endpoint, model, collection key) are in line with other commerce resources and correctly encode the nested /orders/{order_id}/assets path.

@robcsegal robcsegal force-pushed the MPT-16319-add-missing-commerce-orders-assets-endpoints branch from 36a63cd to 3e6f9ff Compare December 10, 2025 02:27
Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/unit/resources/commerce/test_orders.py (1)

6-9: Assets tests correctly validate service wiring

The new tests exercise OrdersService.assets() / AsyncOrdersService.assets() as expected, asserting both the concrete service type and endpoint_params={"order_id": "ORD-123"}, which matches the production implementations. This gives good coverage of the new entry points. If you ever want to DRY things up, you could mirror the subscription tests by reusing the orders_service / async_orders_service fixtures here too, but that’s purely optional.

Also applies to: 251-267

mpt_api_client/resources/commerce/orders_asset.py (1)

1-70: OrdersAsset services and render endpoints are wired correctly; consider cleaning up noqa markers

The model, config, and sync/async services follow the established pattern in this client: the endpoint template, mixins, and render()/async render() calls into _resource_do_request(..., "render") are all consistent and should produce the expected /orders/{order_id}/assets/{asset_id}/render URLs returning markdown text.

The only minor clean-up is the # noqa: WPS215 on the two service class definitions: if you’re no longer relying on that rule from your style checker, you can drop those comments to avoid “unused noqa” noise:

-class OrdersAssetService(  # noqa: WPS215
+class OrdersAssetService(
@@
-class AsyncOrdersAssetService(  # noqa: WPS215
+class AsyncOrdersAssetService(
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36a63cd and 3e6f9ff.

📒 Files selected for processing (4)
  • mpt_api_client/resources/commerce/orders.py (3 hunks)
  • mpt_api_client/resources/commerce/orders_asset.py (1 hunks)
  • tests/unit/resources/commerce/test_orders.py (2 hunks)
  • tests/unit/resources/commerce/test_orders_asset.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/resources/commerce/test_orders_asset.py
🧰 Additional context used
🧬 Code graph analysis (2)
tests/unit/resources/commerce/test_orders.py (3)
mpt_api_client/resources/commerce/orders_asset.py (2)
  • AsyncOrdersAssetService (48-70)
  • OrdersAssetService (23-45)
tests/unit/conftest.py (2)
  • http_client (17-18)
  • async_http_client (22-23)
mpt_api_client/resources/commerce/orders.py (2)
  • assets (122-134)
  • assets (240-252)
mpt_api_client/resources/commerce/orders_asset.py (5)
mpt_api_client/http/async_service.py (1)
  • AsyncService (12-80)
mpt_api_client/http/service.py (1)
  • Service (12-80)
mpt_api_client/http/mixins.py (4)
  • AsyncCollectionMixin (538-605)
  • AsyncManagedResourceMixin (622-625)
  • CollectionMixin (469-535)
  • ManagedResourceMixin (618-619)
mpt_api_client/models/model.py (1)
  • Model (65-125)
mpt_api_client/http/types.py (1)
  • text (36-38)
🪛 Ruff (0.14.8)
mpt_api_client/resources/commerce/orders_asset.py

23-23: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)


48-48: Unused noqa directive (unknown: WPS215)

Remove unused noqa directive

(RUF100)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
mpt_api_client/resources/commerce/orders.py (1)

12-15: Assets accessors mirror existing subscriptions pattern and look correct

The sync and async assets(order_id) methods cleanly construct OrdersAssetService / AsyncOrdersAssetService with endpoint_params={"order_id": order_id}, consistent with the subscriptions helpers and the OrdersAssetServiceConfig endpoint template. The imports and type hints line up with the new module. No issues from my side.

Also applies to: 122-135, 240-252

@d3rky d3rky force-pushed the MPT-16319-add-missing-commerce-orders-assets-endpoints branch from 3e6f9ff to 8d31267 Compare December 10, 2025 14:09
@sonarqubecloud
Copy link

@robcsegal robcsegal merged commit 5665533 into main Dec 10, 2025
6 checks passed
@robcsegal robcsegal deleted the MPT-16319-add-missing-commerce-orders-assets-endpoints branch December 10, 2025 14:36
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.

4 participants