Skip to content

Conversation

@robcsegal
Copy link
Contributor

@robcsegal robcsegal commented Dec 13, 2025

Added e2e tests for commerce assets

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

Summary by CodeRabbit

  • New Features

    • Asset render operation now returns rendered template text instead of a JSON object.
  • Tests

    • Added comprehensive end-to-end test suites (sync & async) covering create, read, update, delete, list, filter, not-found handling, terminate, and render flows with teardown fixtures.
  • Chores

    • Added new configuration keys for commerce assets and new test fixtures exposing asset and agreement IDs.

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

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

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

Generated by 🚫 dangerJS against 5211e77

@coderabbitai
Copy link

coderabbitai bot commented Dec 13, 2025

Walkthrough

This pull request adds comprehensive end-to-end testing infrastructure for the commerce assets API. Changes include configuration keys for asset identifiers, a return type change for the asset render method from AssetTemplate to str, new pytest fixtures for asset operations, and two new E2E test modules (sync and async) covering CRUD and query operations.

Changes

Cohort / File(s) Summary
Configuration
e2e_config.test.json
Added 5 new commerce asset configuration keys: commerce.assets.id, commerce.assets.agreement.id, commerce.assets.order.id, commerce.assets.product.item.id, and commerce.assets.product.template.id
API Client
mpt_api_client/resources/commerce/assets.py
Updated render() method return type from AssetTemplate to str in both AssetService and AsyncAssetService; implementations now return response.text instead of AssetTemplate.from_response()
E2E Test Fixtures
tests/e2e/commerce/asset/conftest.py, tests/e2e/commerce/conftest.py
Added 5 new pytest fixtures: agreement_asset_id(), invalid_agreement_asset_id(), asset_factory() (factory fixture), asset_item_id(), and asset_agreement_id() to support asset testing
E2E Test Suites
tests/e2e/commerce/asset/test_async_asset.py, tests/e2e/commerce/asset/test_sync_asset.py
Added 9 async test functions and corresponding sync equivalents covering asset CRUD operations: get by ID, list, filter (RQLQuery-based), create, update, terminate, render; includes created_asset fixture with teardown logic

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Return type change verification: Confirm the render() method return type change in assets.py is consistent with all call sites and that returning response.text instead of parsed object is intentional
  • Fixture dependencies: Verify fixture chaining and configuration key access are correct across conftest.py files
  • Teardown logic: Review the created_asset fixture teardown handling of MPTAPIError during asset termination
  • Test assertions: Validate that all 9 test cases properly assert on results and error conditions

Possibly related PRs

Suggested reviewers

  • jentyk
  • d3rky
  • alephsur
  • ruben-sebrango
  • albertsola
  • svazquezco

Poem

🐰 With assets rendered as simple strings,
And fixtures ready for testing things,
E2E tests hop through creation's flight,
Configure, create, and terminate right! 🎭

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.79% 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
Title check ✅ Passed The title clearly and specifically describes the main change: addition of end-to-end tests for commerce assets, which aligns with the changeset modifications across test files and configuration.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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-16279-add-e-2-e-tests-for-commerce-assets

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.

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/e2e/commerce/asset/test_sync_asset.py (1)

19-22: Remove or update the noqa directive.

The noqa: WPS421 directive references a wemake-python-styleguide rule, but Ruff flags it as unknown. If the project uses Ruff's print detection, use noqa: T201 instead, or remove the directive entirely if print statements are acceptable in test teardown.

Apply this diff:

-        print(f"TEARDOWN - Unable to terminate asset: {getattr(error, 'title', str(error))}")  # noqa: WPS421
+        print(f"TEARDOWN - Unable to terminate asset: {getattr(error, 'title', str(error))}")  # noqa: T201
tests/e2e/commerce/asset/test_async_asset.py (1)

19-22: Remove or update the noqa directive.

The noqa: WPS421 directive references a wemake-python-styleguide rule, but Ruff flags it as unknown. If the project uses Ruff's print detection, use noqa: T201 instead, or remove the directive entirely if print statements are acceptable in test teardown.

Apply this diff:

-        print(f"TEARDOWN - Unable to terminate asset: {getattr(error, 'title', str(error))}")  # noqa: WPS421
+        print(f"TEARDOWN - Unable to terminate asset: {getattr(error, 'title', str(error))}")  # noqa: T201
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4ca602 and 9f27364.

📒 Files selected for processing (6)
  • e2e_config.test.json (1 hunks)
  • mpt_api_client/resources/commerce/assets.py (3 hunks)
  • tests/e2e/commerce/asset/conftest.py (1 hunks)
  • tests/e2e/commerce/asset/test_async_asset.py (1 hunks)
  • tests/e2e/commerce/asset/test_sync_asset.py (1 hunks)
  • tests/e2e/commerce/conftest.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-27T00:05:36.356Z
Learnt from: robcsegal
Repo: softwareone-platform/mpt-api-python-client PR: 131
File: tests/e2e/conftest.py:0-0
Timestamp: 2025-11-27T00:05:36.356Z
Learning: When reviewing PRs that add fixtures to a parent conftest that may duplicate fixtures in child conftest files, do not suggest removing the duplicates from child conftest files that are outside the scope of the PR's changes.

Applied to files:

  • tests/e2e/commerce/conftest.py
📚 Learning: 2025-12-12T15:02:20.732Z
Learnt from: robcsegal
Repo: softwareone-platform/mpt-api-python-client PR: 160
File: tests/e2e/commerce/agreement/attachment/test_async_agreement_attachment.py:55-58
Timestamp: 2025-12-12T15:02:20.732Z
Learning: In pytest with pytest-asyncio, if a test function uses async fixtures but contains no await, declare the test function as def (synchronous) instead of async def. Pytest-asyncio will resolve the async fixtures automatically; this avoids linter complaints about unnecessary async functions. This pattern applies to any test file under the tests/ directory that uses such fixtures.

Applied to files:

  • tests/e2e/commerce/conftest.py
  • tests/e2e/commerce/asset/conftest.py
  • tests/e2e/commerce/asset/test_async_asset.py
  • tests/e2e/commerce/asset/test_sync_asset.py
🧬 Code graph analysis (4)
tests/e2e/commerce/conftest.py (1)
tests/e2e/conftest.py (1)
  • e2e_config (89-92)
tests/e2e/commerce/asset/conftest.py (2)
tests/e2e/conftest.py (1)
  • e2e_config (89-92)
tests/e2e/commerce/conftest.py (2)
  • asset_item_id (15-16)
  • asset_agreement_id (20-21)
mpt_api_client/resources/commerce/assets.py (1)
mpt_api_client/http/types.py (1)
  • text (36-38)
tests/e2e/commerce/asset/test_sync_asset.py (7)
mpt_api_client/exceptions.py (1)
  • MPTAPIError (20-42)
mpt_api_client/rql/query_builder.py (1)
  • RQLQuery (115-524)
tests/e2e/commerce/asset/test_async_asset.py (5)
  • created_asset (10-22)
  • test_get_asset_by_id (25-28)
  • test_list_assets (31-36)
  • test_get_asset_by_id_not_found (39-41)
  • test_filter_assets (44-54)
tests/e2e/conftest.py (1)
  • mpt_vendor (19-20)
tests/e2e/commerce/asset/conftest.py (3)
  • asset_factory (15-37)
  • agreement_asset_id (5-6)
  • invalid_agreement_asset_id (10-11)
mpt_api_client/resources/commerce/assets.py (4)
  • terminate (42-50)
  • terminate (76-87)
  • render (52-63)
  • render (89-100)
mpt_api_client/models/model.py (1)
  • id (119-121)
🪛 Ruff (0.14.8)
tests/e2e/commerce/asset/test_async_asset.py

22-22: Unused noqa directive (unknown: WPS421)

Remove unused noqa directive

(RUF100)

tests/e2e/commerce/asset/test_sync_asset.py

22-22: Unused noqa directive (unknown: WPS421)

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 (7)
tests/e2e/commerce/conftest.py (1)

14-21: LGTM!

The new fixtures follow the established pattern and cleanly expose asset-specific IDs from the E2E configuration.

tests/e2e/commerce/asset/test_sync_asset.py (1)

25-83: LGTM!

The test suite provides comprehensive coverage of asset operations including CRUD, filtering, and rendering. The test structure is clean and follows pytest conventions.

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

52-63: LGTM - Breaking change is consistent.

Both sync and async render methods now return a string instead of an AssetTemplate object. This is a breaking API change, but it's implemented consistently across both methods and the E2E tests validate the new behavior.

Also applies to: 89-100

tests/e2e/commerce/asset/conftest.py (1)

4-37: LGTM!

The fixtures are well-structured and follow established patterns. The asset_factory provides a flexible way to create asset test data with sensible defaults.

tests/e2e/commerce/asset/test_async_asset.py (2)

57-60: LGTM - Correct usage of sync test with async fixture.

This test correctly uses def instead of async def because it uses an async fixture but contains no await. Pytest-asyncio will resolve the async fixture automatically, as per the project pattern.


25-83: LGTM!

The async test suite mirrors the sync tests with proper async/await usage and provides comprehensive E2E coverage of asset operations.

e2e_config.test.json (1)

29-33: No action needed on empty template ID.

The commerce.assets.product.template.id key is not referenced in the tests, so the empty string value does not affect test execution.

@robcsegal robcsegal force-pushed the MPT-16279-add-e-2-e-tests-for-commerce-assets branch from 9f27364 to 5211e77 Compare December 15, 2025 13:54
@robcsegal robcsegal changed the title [MPT-16279] Added seeding and e2e tests for commerce assets [MPT-16279] Added e2e tests for commerce assets Dec 15, 2025
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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mpt_api_client/resources/commerce/assets.py (1)

52-63: Fix sync docstring for consistency with async version

The sync render docstring says "Render asset template json." but should say "Render asset template string." to match the async version and accurately reflect that the method returns raw text content.

    def render(self, asset_id: str) -> str:
        """Renders the template for the given Asset id.

        Args:
            asset_id: Asset ID.

        Returns:
-            Render asset template json.
+            Rendered asset template string.
🧹 Nitpick comments (1)
tests/e2e/commerce/asset/test_async_asset.py (1)

57-61: Good use of sync test with async fixture (matches agreed pattern)

test_create_asset is a synchronous def that relies on the async created_asset fixture without doing its own await, which aligns with the preferred pytest‑asyncio pattern for avoiding unnecessary async def tests. This is consistent with prior decisions for this repo.

Based on learnings, this is the intended style for such tests.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f27364 and 5211e77.

📒 Files selected for processing (6)
  • e2e_config.test.json (1 hunks)
  • mpt_api_client/resources/commerce/assets.py (3 hunks)
  • tests/e2e/commerce/asset/conftest.py (1 hunks)
  • tests/e2e/commerce/asset/test_async_asset.py (1 hunks)
  • tests/e2e/commerce/asset/test_sync_asset.py (1 hunks)
  • tests/e2e/commerce/conftest.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • e2e_config.test.json
  • tests/e2e/commerce/asset/conftest.py
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-27T00:05:36.356Z
Learnt from: robcsegal
Repo: softwareone-platform/mpt-api-python-client PR: 131
File: tests/e2e/conftest.py:0-0
Timestamp: 2025-11-27T00:05:36.356Z
Learning: When reviewing PRs that add fixtures to a parent conftest that may duplicate fixtures in child conftest files, do not suggest removing the duplicates from child conftest files that are outside the scope of the PR's changes.

Applied to files:

  • tests/e2e/commerce/conftest.py
📚 Learning: 2025-12-12T15:02:20.732Z
Learnt from: robcsegal
Repo: softwareone-platform/mpt-api-python-client PR: 160
File: tests/e2e/commerce/agreement/attachment/test_async_agreement_attachment.py:55-58
Timestamp: 2025-12-12T15:02:20.732Z
Learning: In pytest with pytest-asyncio, if a test function uses async fixtures but contains no await, declare the test function as def (synchronous) instead of async def. Pytest-asyncio will resolve the async fixtures automatically; this avoids linter complaints about unnecessary async functions. This pattern applies to any test file under the tests/ directory that uses such fixtures.

Applied to files:

  • tests/e2e/commerce/conftest.py
  • tests/e2e/commerce/asset/test_async_asset.py
  • tests/e2e/commerce/asset/test_sync_asset.py
🧬 Code graph analysis (4)
tests/e2e/commerce/conftest.py (1)
tests/e2e/conftest.py (1)
  • e2e_config (89-92)
tests/e2e/commerce/asset/test_async_asset.py (5)
mpt_api_client/exceptions.py (1)
  • MPTAPIError (20-42)
tests/e2e/conftest.py (1)
  • async_mpt_vendor (24-27)
tests/e2e/commerce/asset/conftest.py (3)
  • asset_factory (15-37)
  • agreement_asset_id (5-6)
  • invalid_agreement_asset_id (10-11)
mpt_api_client/resources/commerce/assets.py (4)
  • terminate (42-50)
  • terminate (76-87)
  • render (52-63)
  • render (89-100)
mpt_api_client/models/model.py (1)
  • id (119-121)
mpt_api_client/resources/commerce/assets.py (1)
mpt_api_client/http/types.py (1)
  • text (36-38)
tests/e2e/commerce/asset/test_sync_asset.py (5)
mpt_api_client/exceptions.py (1)
  • MPTAPIError (20-42)
tests/e2e/conftest.py (1)
  • mpt_vendor (19-20)
tests/e2e/commerce/asset/conftest.py (3)
  • asset_factory (15-37)
  • agreement_asset_id (5-6)
  • invalid_agreement_asset_id (10-11)
mpt_api_client/resources/commerce/assets.py (4)
  • terminate (42-50)
  • terminate (76-87)
  • render (52-63)
  • render (89-100)
mpt_api_client/models/model.py (1)
  • id (119-121)
🪛 Ruff (0.14.8)
tests/e2e/commerce/asset/test_async_asset.py

22-22: Unused noqa directive (unknown: WPS421)

Remove unused noqa directive

(RUF100)

tests/e2e/commerce/asset/test_sync_asset.py

22-22: Unused noqa directive (unknown: WPS421)

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 (2)
tests/e2e/commerce/conftest.py (1)

44-51: Asset ID fixtures are consistent with existing e2e config usage

asset_item_id and asset_agreement_id follow the same pattern as other commerce fixtures and correctly map to the commerce.assets.* keys. No changes needed.

tests/e2e/commerce/asset/test_sync_asset.py (1)

25-83: Sync asset E2E flows look comprehensive and robust

The tests exercise core asset flows (get, list, not-found, filter, create, update, terminate, render) and reuse the created_asset fixture cleanly; double-termination is safely handled by the teardown’s MPTAPIError catch. This gives good end‑to‑end coverage for the sync asset API.

@sonarqubecloud
Copy link

@robcsegal robcsegal requested a review from albertsola December 15, 2025 14:15
@d3rky d3rky merged commit a6a3cff into main Dec 15, 2025
8 checks passed
@d3rky d3rky deleted the MPT-16279-add-e-2-e-tests-for-commerce-assets branch December 15, 2025 14:29
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