-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-18374 Add Helpdesk Forms API services and tests #245
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
Merged
Merged
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| 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, ResourceData | ||
|
|
||
|
|
||
| class Form(Model): | ||
| """Helpdesk Form resource.""" | ||
|
|
||
|
|
||
| class FormsServiceConfig: | ||
| """Helpdesk Forms service configuration.""" | ||
|
|
||
| _endpoint = "/public/v1/helpdesk/forms" | ||
| _model_class = Form | ||
| _collection_key = "data" | ||
|
|
||
|
|
||
| class FormsService( | ||
| ManagedResourceMixin[Form], | ||
| CollectionMixin[Form], | ||
| Service[Form], | ||
| FormsServiceConfig, | ||
| ): | ||
| """Helpdesk Forms service.""" | ||
|
|
||
| def publish(self, resource_id: str, resource_data: ResourceData | None = None) -> Form: | ||
| """Switch form to published state.""" | ||
| return self._resource_action(resource_id, "POST", "publish", json=resource_data) | ||
|
|
||
| def unpublish(self, resource_id: str, resource_data: ResourceData | None = None) -> Form: | ||
| """Switch form to unpublished state.""" | ||
| return self._resource_action(resource_id, "POST", "unpublish", json=resource_data) | ||
|
|
||
|
|
||
| class AsyncFormsService( | ||
| AsyncManagedResourceMixin[Form], | ||
| AsyncCollectionMixin[Form], | ||
| AsyncService[Form], | ||
| FormsServiceConfig, | ||
| ): | ||
| """Async Helpdesk Forms service.""" | ||
|
|
||
| async def publish(self, resource_id: str, resource_data: ResourceData | None = None) -> Form: | ||
| """Switch form to published state.""" | ||
| return await self._resource_action(resource_id, "POST", "publish", json=resource_data) | ||
|
|
||
| async def unpublish(self, resource_id: str, resource_data: ResourceData | None = None) -> Form: | ||
| """Switch form to unpublished state.""" | ||
| return await self._resource_action(resource_id, "POST", "unpublish", json=resource_data) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
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,33 @@ | ||
| import pytest | ||
|
|
||
| from tests.e2e.helper import ( | ||
| async_create_fixture_resource_and_delete, | ||
| create_fixture_resource_and_delete, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def form_data(short_uuid): | ||
| return { | ||
| "name": f"E2E Helpdesk Form {short_uuid}", | ||
| "description": "E2E Created Helpdesk Form", | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_form_id(): | ||
| return "FRM-0000-0000" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_form(mpt_ops, form_data): | ||
| with create_fixture_resource_and_delete(mpt_ops.helpdesk.forms, form_data) as form: | ||
| yield form | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_created_form(async_mpt_ops, form_data): | ||
| async with async_create_fixture_resource_and_delete( | ||
| async_mpt_ops.helpdesk.forms, form_data | ||
| ) as form: | ||
| yield form |
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,60 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_get_form(async_mpt_ops, async_created_form): | ||
| result = await async_mpt_ops.helpdesk.forms.get(async_created_form.id) | ||
|
|
||
| assert result.id == async_created_form.id | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_list_forms(async_mpt_ops): | ||
| result = await async_mpt_ops.helpdesk.forms.fetch_page(limit=1) | ||
|
|
||
| assert len(result) > 0 | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_create_form(async_created_form): | ||
| result = async_created_form | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_update_form(async_mpt_ops, async_created_form, short_uuid): | ||
| update_data = {"description": f"e2e update {short_uuid}"} | ||
|
|
||
| result = await async_mpt_ops.helpdesk.forms.update(async_created_form.id, update_data) | ||
|
|
||
| assert result.id == async_created_form.id | ||
| assert result.to_dict().get("description") == update_data["description"] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_publish_form(async_mpt_ops, async_created_form): | ||
| result = await async_mpt_ops.helpdesk.forms.publish(async_created_form.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_unpublish_form(async_mpt_ops, async_created_form): | ||
| result = await async_mpt_ops.helpdesk.forms.unpublish(async_created_form.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| async def test_delete_form(async_mpt_ops, async_created_form): | ||
| await async_mpt_ops.helpdesk.forms.delete(async_created_form.id) # act | ||
|
|
||
|
|
||
| async def test_not_found(async_mpt_ops, invalid_form_id): | ||
| with pytest.raises(MPTAPIError): | ||
| await async_mpt_ops.helpdesk.forms.get(invalid_form_id) |
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,60 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_get_form(mpt_ops, created_form): | ||
| result = mpt_ops.helpdesk.forms.get(created_form.id) | ||
|
|
||
| assert result.id == created_form.id | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_list_forms(mpt_ops): | ||
| result = mpt_ops.helpdesk.forms.fetch_page(limit=1) | ||
|
|
||
| assert len(result) > 0 | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_create_form(created_form): | ||
| result = created_form | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_update_form(mpt_ops, created_form, short_uuid): | ||
| update_data = {"description": f"e2e update {short_uuid}"} | ||
|
|
||
| result = mpt_ops.helpdesk.forms.update(created_form.id, update_data) | ||
|
|
||
| assert result.id == created_form.id | ||
| assert result.to_dict().get("description") == update_data["description"] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_publish_form(mpt_ops, created_form): | ||
| result = mpt_ops.helpdesk.forms.publish(created_form.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_unpublish_form(mpt_ops, created_form): | ||
| result = mpt_ops.helpdesk.forms.unpublish(created_form.id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Unskip after MPT-19124 completed") | ||
| def test_delete_form(mpt_ops, created_form): | ||
| mpt_ops.helpdesk.forms.delete(created_form.id) # act | ||
|
|
||
|
|
||
| def test_not_found(mpt_ops, invalid_form_id): | ||
| with pytest.raises(MPTAPIError): | ||
| mpt_ops.helpdesk.forms.get(invalid_form_id) |
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,93 @@ | ||
| import httpx | ||
| import pytest | ||
| import respx | ||
|
|
||
| from mpt_api_client.resources.helpdesk.forms import AsyncFormsService, Form, FormsService | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def forms_service(http_client): | ||
| return FormsService(http_client=http_client) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_forms_service(async_http_client): | ||
| return AsyncFormsService(http_client=async_http_client) | ||
|
|
||
|
|
||
| def test_endpoint(forms_service): | ||
| result = forms_service.path == "/public/v1/helpdesk/forms" | ||
|
|
||
| assert result is True | ||
|
|
||
|
|
||
| def test_async_endpoint(async_forms_service): | ||
| result = async_forms_service.path == "/public/v1/helpdesk/forms" | ||
|
|
||
| assert result is True | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "method", | ||
| ["get", "create", "update", "delete", "fetch_page", "iterate", "publish", "unpublish"], | ||
| ) | ||
| def test_methods_present(forms_service, method): | ||
| result = hasattr(forms_service, method) | ||
|
|
||
| assert result is True | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "method", | ||
| ["get", "create", "update", "delete", "fetch_page", "iterate", "publish", "unpublish"], | ||
| ) | ||
| def test_async_methods_present(async_forms_service, method): | ||
| result = hasattr(async_forms_service, method) | ||
|
|
||
| assert result is True | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("action", ["publish", "unpublish"]) | ||
| def test_custom_resource_actions(forms_service, action): | ||
| response_expected_data = {"id": "FRM-1234-5678", "status": "Updated"} | ||
| with respx.mock: | ||
| mock_route = respx.post( | ||
| f"https://api.example.com/public/v1/helpdesk/forms/FRM-1234-5678/{action}" | ||
| ).mock( | ||
| return_value=httpx.Response( | ||
| status_code=httpx.codes.OK, | ||
| headers={"content-type": "application/json"}, | ||
| json=response_expected_data, | ||
| ) | ||
| ) | ||
|
|
||
| result = getattr(forms_service, action)("FRM-1234-5678") | ||
|
|
||
| assert mock_route.call_count == 1 | ||
| request = mock_route.calls[0].request | ||
| assert request.content == b"" | ||
| assert result.to_dict() == response_expected_data | ||
| assert isinstance(result, Form) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("action", ["publish", "unpublish"]) | ||
| async def test_async_custom_resource_actions(async_forms_service, action): | ||
| response_expected_data = {"id": "FRM-1234-5678", "status": "Updated"} | ||
| with respx.mock: | ||
| mock_route = respx.post( | ||
| f"https://api.example.com/public/v1/helpdesk/forms/FRM-1234-5678/{action}" | ||
| ).mock( | ||
| return_value=httpx.Response( | ||
| status_code=httpx.codes.OK, | ||
| headers={"content-type": "application/json"}, | ||
| json=response_expected_data, | ||
| ) | ||
| ) | ||
|
|
||
| result = await getattr(async_forms_service, action)("FRM-1234-5678") | ||
|
|
||
| assert mock_route.call_count == 1 | ||
| request = mock_route.calls[0].request | ||
| assert request.content == b"" | ||
| assert result.to_dict() == response_expected_data | ||
| assert isinstance(result, Form) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.