-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-14900 E2E tests for catalog pricing-policies attachments #133
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def attachment_id(created_attachment): | ||
| return created_attachment.id | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def attachment_data(): | ||
| return { | ||
| "name": "e2e test attachment - please delete", | ||
| "description": "E2E test attachment for automated testing", | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def attachment_service(mpt_ops, pricing_policy_id): | ||
| return mpt_ops.catalog.pricing_policies.attachments(pricing_policy_id) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_attachment(attachment_service, attachment_data, pdf_fd): | ||
| attachment = attachment_service.create(attachment_data, file=pdf_fd) | ||
| yield attachment | ||
| try: | ||
| attachment_service.delete(attachment.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete attachment {attachment.id}: {error.title}") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_attachment_service(async_mpt_ops, pricing_policy_id): | ||
| return async_mpt_ops.catalog.pricing_policies.attachments(pricing_policy_id) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_attachment_async(async_attachment_service, attachment_data, pdf_fd): | ||
| attachment = await async_attachment_service.create(attachment_data, file=pdf_fd) | ||
| yield attachment | ||
| try: | ||
| await async_attachment_service.delete(attachment.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete attachment {attachment.id}: {error.title}") | ||
|
|
||
|
|
||
| def test_create_attachment_async(created_attachment_async, attachment_data): | ||
| result = created_attachment_async | ||
|
|
||
| assert result.name == attachment_data["name"] | ||
| assert result.description == attachment_data["description"] | ||
|
|
||
|
|
||
| async def test_update_attachment_async(async_attachment_service, created_attachment_async): | ||
| update_data = {"name": "Updated e2e test attachment - please delete"} | ||
|
|
||
| result = await async_attachment_service.update(created_attachment_async.id, update_data) | ||
|
|
||
| assert result.name == update_data["name"] | ||
|
|
||
|
|
||
| async def test_get_attachment_async(async_attachment_service, attachment_id): | ||
| result = await async_attachment_service.get(attachment_id) | ||
|
|
||
| assert result.id == attachment_id | ||
|
|
||
|
|
||
| async def test_download_attachment_async(async_attachment_service, attachment_id): | ||
| result = await async_attachment_service.download(attachment_id) | ||
|
|
||
| assert result.file_contents is not None | ||
| assert result.filename == "empty.pdf" | ||
|
|
||
|
|
||
| async def test_iterate_attachments_async(async_attachment_service, created_attachment_async): | ||
| result = [att async for att in async_attachment_service.iterate()] | ||
|
|
||
| assert any(att.id == created_attachment_async.id for att in result) | ||
|
|
||
|
|
||
| async def test_filter_attachments_async(async_attachment_service, created_attachment_async): | ||
| filtered_service = async_attachment_service.filter(RQLQuery(id=created_attachment_async.id)) | ||
|
|
||
| result = [att async for att in filtered_service.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
| assert result[0].id == created_attachment_async.id | ||
|
|
||
|
|
||
| async def test_not_found_async(async_attachment_service): | ||
| with pytest.raises(MPTAPIError): | ||
| await async_attachment_service.get("ATT-000-000-000") | ||
|
|
||
|
|
||
| async def test_delete_attachment_async(async_attachment_service, created_attachment_async): | ||
| await async_attachment_service.delete(created_attachment_async.id) | ||
|
|
||
| with pytest.raises(MPTAPIError): | ||
| await async_attachment_service.get(created_attachment_async.id) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| def test_create_attachment(created_attachment, attachment_data): | ||
| result = created_attachment | ||
|
|
||
| assert result.name == attachment_data["name"] | ||
| assert result.description == attachment_data["description"] | ||
|
|
||
|
|
||
| def test_update_attachment(attachment_service, created_attachment): | ||
| update_data = {"name": "Updated e2e test attachment - please delete"} | ||
|
|
||
| result = attachment_service.update(created_attachment.id, update_data) | ||
|
|
||
| assert result.name == update_data["name"] | ||
|
|
||
|
|
||
| def test_get_attachment(attachment_service, attachment_id): | ||
| result = attachment_service.get(attachment_id) | ||
|
|
||
| assert result.id == attachment_id | ||
|
|
||
|
|
||
| def test_download_attachment(attachment_service, attachment_id): | ||
| result = attachment_service.download(attachment_id) | ||
|
|
||
| assert result.file_contents is not None | ||
| assert result.filename == "empty.pdf" | ||
|
|
||
|
|
||
| def test_iterate_attachments(attachment_service, created_attachment): | ||
| result = list(attachment_service.iterate()) | ||
|
|
||
| assert any(att.id == created_attachment.id for att in result) | ||
|
|
||
|
|
||
| def test_filter_attachments(attachment_service, created_attachment): | ||
| result = list(attachment_service.filter(RQLQuery(id=created_attachment.id)).iterate()) | ||
|
|
||
| assert len(result) == 1 | ||
| assert result[0].id == created_attachment.id | ||
|
|
||
|
|
||
| def test_not_found(attachment_service): | ||
| with pytest.raises(MPTAPIError): | ||
| attachment_service.get("ATT-000-000-000") | ||
|
|
||
|
|
||
| def test_delete_attachment(attachment_service, created_attachment): | ||
| attachment_service.delete(created_attachment.id) | ||
|
|
||
| with pytest.raises(MPTAPIError): | ||
| attachment_service.get(created_attachment.id) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,12 +35,10 @@ async def test_get_pricing_policy(async_pricing_policies_service, async_created_ | |
| assert result.id == async_created_pricing_policy.id | ||
|
|
||
|
|
||
| async def test_get_pricing_policy_by_id( | ||
| async_pricing_policies_service, async_created_pricing_policy | ||
| ): | ||
| result = await async_pricing_policies_service.get(async_created_pricing_policy.id) | ||
| async def test_get_pricing_policy_by_id(async_pricing_policies_service, pricing_policy_id): | ||
| result = await async_pricing_policies_service.get(pricing_policy_id) | ||
|
|
||
| assert result.id == async_created_pricing_policy.id | ||
| assert result.id == pricing_policy_id | ||
|
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent fixture usage in async test. This async test now uses This creates an inconsistency where async tests have mixed dependencies on both sync and async fixtures. For consistency and clarity, async tests should use async fixtures. Based on the reviewer's comment about following the AAA pattern from PR #134, consider reverting this change to use -async def test_get_pricing_policy_by_id(async_pricing_policies_service, pricing_policy_id):
- result = await async_pricing_policies_service.get(pricing_policy_id)
+async def test_get_pricing_policy_by_id(async_pricing_policies_service, async_created_pricing_policy):
+ result = await async_pricing_policies_service.get(async_created_pricing_policy.id)
- assert result.id == pricing_policy_id
+ assert result.id == async_created_pricing_policy.id
🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| async def test_iterate_pricing_policies( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Refactor to follow AAA (Arrange-Act-Assert) pattern.
This test doesn't follow the AAA pattern requested by the reviewer. The "Act" step (creating the attachment) is hidden in the
created_attachmentfixture, making it unclear what operation is being tested. The test should explicitly callattachment_service.create()to make the action visible.Based on the reviewer's feedback, consider this structure:
🤖 Prompt for AI Agents
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 910
🏁 Script executed:
Length of output: 10072
@jentyk You're absolutely right! I apologize for the confusion. After reviewing PR #134, I can see that the AAA pattern they use does rely on fixtures for setup and teardown.
Looking at examples from PR #134:
The current test in this PR already follows that same pattern:
The test correctly:
resultvariable (act)My previous suggestion to add explicit cleanup and remove the fixture was incorrect. The test structure is actually fine as-is. Thank you for catching that!