Skip to content

Conversation

@albertsola
Copy link
Contributor

@albertsola albertsola commented Feb 2, 2026

Closes MPT-16437

  • Split monolithic mpt_api_client/resources/accounts/mixins.py into focused submodules: activatable_mixin.py, blockable_mixin.py, invitable_mixin.py, validate_mixin.py
  • Added mpt_api_client.resources.accounts.mixins.init to re-export mixins and preserve public import surface
  • Updated imports in account resources (account.py, account_users.py, accounts_users.py, buyers.py, erp_links.py, sellers.py, users.py) to use new submodules/package initializer
  • Reintroduced mixin classes (Activatable/AsyncActivatable, Blockable/AsyncBlockable, Invitable/AsyncInvitable, Validate/AsyncValidate) in their respective files with unchanged public signatures
  • Replaced the large mixed test module with focused tests per mixin and file-related mixins (added test_activatable_mixin.py, test_blockable_mixin.py, test_invitable_mixin.py, test_validate_mixin.py, test_file_mixins.py) and removed tests/unit/resources/accounts/test_mixins.py
  • No behavioral or public API changes; this is a structural/refactor to improve organization and clarity

@albertsola albertsola requested a review from a team as a code owner February 2, 2026 12:01
@albertsola albertsola requested review from d3rky and jentyk February 2, 2026 12:01
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

Mixins for account resources were split into separate submodules, a package-level init was added to re-export them, resource modules' imports were updated to the new paths, the previous monolithic mixins file was removed, and tests were reorganized from one large module into focused per-mixin test files.

Changes

Cohort / File(s) Summary
Mixin core removed
mpt_api_client/resources/accounts/mixins.py
Removed the single-file mixins module and all mixin class definitions.
New mixin submodules
mpt_api_client/resources/accounts/mixins/activatable_mixin.py, mpt_api_client/resources/accounts/mixins/blockable_mixin.py, mpt_api_client/resources/accounts/mixins/invitable_mixin.py, mpt_api_client/resources/accounts/mixins/validate_mixin.py
Added dedicated modules implementing synchronous and asynchronous variants of Activatable, Blockable, Invitable, and Validate mixins; each calls _resource_action and uses ResourceData typing.
Mixin package initializer
mpt_api_client/resources/accounts/mixins/__init__.py
New package __init__ re-exports the mixin classes via __all__ to preserve import compatibility.
Resource import updates
mpt_api_client/resources/accounts/account.py, mpt_api_client/resources/accounts/buyers.py, mpt_api_client/resources/accounts/sellers.py, mpt_api_client/resources/accounts/account_users.py, mpt_api_client/resources/accounts/accounts_users.py, mpt_api_client/resources/accounts/erp_links.py, mpt_api_client/resources/accounts/users.py
Updated imports to reference mixins from their new submodule paths (e.g., ...mixins.activatable_mixin, ...mixins.blockable_mixin, ...mixins.invitable_mixin, ...mixins.validate_mixin); no public signatures changed.
Tests removed
tests/unit/resources/accounts/test_mixins.py
Deleted the monolithic test module that previously covered multiple mixins.
New focused tests
tests/unit/resources/accounts/mixins/test_activatable_mixin.py, tests/unit/resources/accounts/mixins/test_blockable_mixin.py, tests/unit/resources/accounts/mixins/test_invitable_mixin.py, tests/unit/resources/accounts/mixins/test_validate_mixin.py, tests/unit/resources/accounts/mixins/test_file_mixins.py
Added separate unit test modules for each mixin (and file mixins) with dummy services, fixtures, and sync/async tests verifying endpoint construction, request payloads, and response→model mapping.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed The PR title contains exactly one Jira issue key MPT-16437 in the correct format, properly positioned at the beginning.
Test Coverage Required ✅ Passed PR modifies 13 code files in mpt_api_client/resources/accounts/ and includes comprehensive test reorganization with 5 new test files and updates to existing test files, demonstrating adequate test coverage for code changes.
Single Commit Required ✅ Passed The pull request contains exactly one commit (980ba89 - "MPT-16437 Reorganise resource accounts mixins structure"), satisfying the single commit requirement.

✏️ 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.

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

🤖 Fix all issues with AI agents
In `@tests/unit/resources/accounts/mixins/test_activatable_mixin.py`:
- Around line 132-139: The async test function test_async_actions_no_data is
missing the pytest asyncio marker; add the `@pytest.mark.asyncio` decorator
directly above the async def test_async_actions_no_data(...) to ensure the
coroutine is executed by pytest-asyncio (and confirm pytest-asyncio is available
in test deps if not already).
🧹 Nitpick comments (2)
mpt_api_client/resources/accounts/mixins/__init__.py (1)

18-18: Remove unused noqa directive.

The # noqa: WPS410 comment is not recognized by Ruff. If you're using wemake-python-styleguide alongside Ruff, this is fine. Otherwise, remove the unused directive.

🧹 Proposed fix
-__all__ = [  # noqa: WPS410
+__all__ = [
tests/unit/resources/accounts/mixins/test_validate_mixin.py (1)

41-46: Consider simplifying tests without parameterization.

The @pytest.mark.parametrize with a single test case adds overhead without providing multiple test scenarios. Since validate is the only action being tested, consider removing the parameterization and passing values directly.

However, if there's intent to add more actions later (e.g., validate_partial), keeping the parameterization structure makes sense for consistency with other test files.

♻️ Optional simplification (if no future actions planned)
-@pytest.mark.parametrize(
-    ("action", "input_status"),
-    [
-        ("validate", {"id": "OBJ-0000-0001", "status": "update"}),
-    ],
-)
-def test_validate_resource_actions(validate_service, action, input_status):
+def test_validate_resource_actions(validate_service):
+    action = "validate"
+    input_status = {"id": "OBJ-0000-0001", "status": "update"}
     request_expected_content = b'{"id":"OBJ-0000-0001","status":"update"}'

@albertsola albertsola force-pushed the MPT-16437/Reorganise-resource-mixins branch from 1950f49 to 35ebf36 Compare February 2, 2026 13:07
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

🤖 Fix all issues with AI agents
In `@tests/unit/resources/accounts/mixins/test_file_mixins.py`:
- Around line 120-235: Remove the redundant `@pytest.mark.asyncio` decorators from
the async test functions (e.g., test_async_create_file_service,
test_async_create_file_service_no_file, test_async_update_file_service,
test_async_update_file_service_no_file) so they rely on pytest's configured
asyncio auto mode; delete the decorator lines (and any direct uses of
pytest.mark.asyncio in this file) while leaving the async def signatures and
test bodies unchanged.

In `@tests/unit/resources/accounts/mixins/test_invitable_mixin.py`:
- Around line 113-147: Remove the redundant `@pytest.mark.asyncio` decorators from
the async test functions in this file: specifically delete the decorator above
test_async_invitable_resource_actions and above
test_async_invitable_resource_actions_no_data (and any other async test
functions in this diff) so they rely on the repo-wide pytest asyncio auto mode;
leave the async def signatures, awaits (e.g., await
getattr(async_invitable_service, action)(...)), and parametrization intact.
🧹 Nitpick comments (1)
tests/unit/resources/accounts/mixins/test_activatable_mixin.py (1)

108-109: Minor inconsistency in @pytest.mark.asyncio usage.

test_async_activatable_resource_actions (line 108) has the @pytest.mark.asyncio decorator, while test_async_actions_no_data (line 139) does not. Since the project uses asyncio_mode = "auto", neither requires the marker. Consider removing it from line 108 for consistency, or adding it to both if you prefer explicit markers.

Based on learnings: In the mpt-api-python-client repository, tests are configured to use pytest asyncio mode auto, which auto-detects async test functions and runs them without requiring pytest.mark.asyncio.

Also applies to: 139-139

@albertsola albertsola force-pushed the MPT-16437/Reorganise-resource-mixins branch from 35ebf36 to 980ba89 Compare February 2, 2026 13:36
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 2, 2026

@albertsola albertsola merged commit 5ce922c into main Feb 2, 2026
4 checks passed
@albertsola albertsola deleted the MPT-16437/Reorganise-resource-mixins branch February 2, 2026 14:09
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.

3 participants