-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-19908: add /integration/installations service #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
albertsola
wants to merge
2
commits into
main
Choose a base branch
from
MPT-19908/integration-installations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| from mpt_api_client.http import AsyncService, Service | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCollectionMixin, | ||
| AsyncManagedResourceMixin, | ||
| CollectionMixin, | ||
| ManagedResourceMixin, | ||
| ) | ||
| from mpt_api_client.models import Model | ||
| from mpt_api_client.models.model import BaseModel | ||
| from mpt_api_client.resources.integration.mixins import ( | ||
| AsyncInstallationMixin, | ||
| InstallationMixin, | ||
| ) | ||
|
|
||
|
|
||
| class Installation(Model): | ||
| """Installation resource. | ||
|
|
||
| Attributes: | ||
| name: Installation name. | ||
| revision: Revision number. | ||
| account: Reference to the account. | ||
| extension: Reference to the extension. | ||
| status: Installation status (Invited, Installed, Uninstalled, Expired). | ||
| configuration: Installation configuration data. | ||
| invitation: Invitation details. | ||
| modules: Modules included in the installation. | ||
| terms: Accepted terms for this installation. | ||
| audit: Audit information (created, updated, invited, installed, expired, uninstalled). | ||
| """ | ||
|
|
||
| name: str | None | ||
| revision: int | None | ||
| account: BaseModel | None | ||
| extension: BaseModel | None | ||
| status: str | None | ||
| configuration: BaseModel | None | ||
| invitation: BaseModel | None | ||
| modules: list[BaseModel] | None | ||
| terms: list[BaseModel] | None | ||
| audit: BaseModel | None | ||
|
|
||
|
|
||
| class InstallationsServiceConfig: | ||
| """Installations service configuration.""" | ||
|
|
||
| _endpoint = "/public/v1/integration/installations" | ||
| _model_class = Installation | ||
| _collection_key = "data" | ||
|
|
||
|
|
||
| class InstallationsService( | ||
| InstallationMixin[Installation], | ||
| ManagedResourceMixin[Installation], | ||
| CollectionMixin[Installation], | ||
| Service[Installation], | ||
| InstallationsServiceConfig, | ||
| ): | ||
| """Sync service for the /public/v1/integration/installations endpoint.""" | ||
|
|
||
|
|
||
| class AsyncInstallationsService( | ||
| AsyncInstallationMixin[Installation], | ||
| AsyncManagedResourceMixin[Installation], | ||
| AsyncCollectionMixin[Installation], | ||
| AsyncService[Installation], | ||
| InstallationsServiceConfig, | ||
| ): | ||
| """Async service for the /public/v1/integration/installations endpoint.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
mpt_api_client/resources/integration/mixins/installation_mixin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| from mpt_api_client.models import ResourceData | ||
|
|
||
|
|
||
| class InstallationMixin[Model]: | ||
| """Mixin that adds installation lifecycle actions: invite, install, uninstall, expire.""" | ||
|
|
||
| def invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Invite an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("invite", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def install(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Mark an installation as installed. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("install", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def uninstall(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Uninstall an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("uninstall", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| def expire(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Expire an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return self._resource(resource_id).post("expire", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
|
|
||
| class AsyncInstallationMixin[Model]: | ||
| """Async mixin for installation lifecycle actions: invite, install, uninstall, expire.""" | ||
|
|
||
| async def invite(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Invite an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("invite", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def install(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Mark an installation as installed. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("install", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def uninstall(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Uninstall an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("uninstall", json=resource_data) # type: ignore[attr-defined, no-any-return] | ||
|
|
||
| async def expire(self, resource_id: str, resource_data: ResourceData | None = None) -> Model: | ||
| """Expire an installation. | ||
|
|
||
| Args: | ||
| resource_id: Installation ID. | ||
| resource_data: Optional request body. | ||
|
|
||
| Returns: | ||
| Updated installation. | ||
| """ | ||
| return await self._resource(resource_id).post("expire", json=resource_data) # type: ignore[attr-defined, no-any-return] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def installations_service(mpt_ops): | ||
| return mpt_ops.integration.installations | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_installations_service(async_mpt_ops): | ||
| return async_mpt_ops.integration.installations | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def installation_id(e2e_config): | ||
| return e2e_config["integration.installation.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def installation_data(): | ||
| return { | ||
| "extension": {"id": "EXT-0000-0000"}, | ||
| "account": {"id": "ACC-0000-0000"}, | ||
| "modules": [], | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_installation(installations_service, installation_data): | ||
| installation = installations_service.create(installation_data) | ||
|
|
||
| yield installation | ||
|
|
||
| try: | ||
| installations_service.delete(installation.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete installation {installation.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_created_installation(async_installations_service, installation_data): | ||
| installation = await async_installations_service.create(installation_data) | ||
|
|
||
| yield installation | ||
|
|
||
| try: | ||
| await async_installations_service.delete(installation.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete installation {installation.id}: {error.title}") # noqa: WPS421 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix formatting to resolve pipeline failure.
The pipeline reports
ruff format --check failed. Removing the@pytest.mark.skipdecorator left an extra blank line, resulting in 3 consecutive blank lines beforetest_create_extension. Ruff format expects exactly 2 blank lines between top-level definitions.🛠️ Proposed fix
pytestmark = [pytest.mark.flaky] - def test_create_extension(async_created_extension, extension_data):🤖 Prompt for AI Agents