-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-14888 Add E2E tests for catalog items #118
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 |
|---|---|---|
| @@ -1,13 +1,16 @@ | ||
| { | ||
| "catalog.product.id": "PRD-7255-3950", | ||
| "accounts.seller.id": "SEL-7310-3075", | ||
| "catalog.product.parameter_group.id": "PGR-7255-3950-0001", | ||
| "catalog.product.parameter.id": "PAR-7255-3950-0016", | ||
| "catalog.product.document.id": "PDC-7255-3950-0001", | ||
| "accounts.account.id": "ACC-9042-0088", | ||
| "accounts.buyer.account.id": "ACC-1086-6867", | ||
| "accounts.buyer.id": "BUY-1591-2112", | ||
| "accounts.user_group.id": "UGR-6822-0561", | ||
| "accounts.module.id": "MOD-1756", | ||
| "accounts.module.name": "Access Management" | ||
| "accounts.module.name": "Access Management", | ||
| "catalog.product.id": "PRD-7255-3950", | ||
| "catalog.product.parameter_group.id": "PGR-7255-3950-0001", | ||
| "catalog.product.item_group.id": "IGR-7255-3950-0001", | ||
| "catalog.product.parameter.id": "PAR-7255-3950-0016", | ||
| "catalog.product.document.id": "PDC-7255-3950-0001", | ||
| "catalog.item.id": "ITM-7255-3950-0001", | ||
| "catalog.unit.id": "UNT-1229" | ||
| } |
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.
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,16 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def item_id(e2e_config): | ||
| return e2e_config.get("catalog.item.id") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def item_group_id(e2e_config): | ||
| return e2e_config.get("catalog.product.item_group.id") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def unit_id(e2e_config): | ||
| return e2e_config.get("catalog.unit.id") |
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,20 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def item_data(short_uuid, product_id, item_group_id, unit_id): | ||
| return { | ||
| "name": "e2e - please delete", | ||
| "description": "e2e - please delete", | ||
| "unit": { | ||
| "id": unit_id, | ||
| }, | ||
| "group": { | ||
| "id": item_group_id, | ||
| }, | ||
| "product": { | ||
| "id": product_id, | ||
| }, | ||
| "terms": {"model": "quantity", "period": "1m", "commitment": "1m"}, | ||
| "externalIds": {"vendor": f"e2e-delete-{short_uuid}"}, | ||
| } |
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 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_created_item(logger, async_mpt_vendor, item_data): | ||
| service = async_mpt_vendor.catalog.items | ||
| item = await service.create(item_data) | ||
| yield item | ||
| try: | ||
| await service.delete(item.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete item {item.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| def test_create_item(async_created_item): | ||
| assert async_created_item.name == "e2e - please delete" | ||
|
|
||
|
|
||
| async def test_update_item(async_mpt_vendor, async_created_item): | ||
| service = async_mpt_vendor.catalog.items | ||
| update_data = {"name": "e2e - delete me (updated)"} | ||
| item = await service.update(async_created_item.id, update_data) | ||
| assert item.name == "e2e - delete me (updated)" | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Leaves test items in the catalog") | ||
| async def test_review_and_publish_item(async_mpt_vendor, async_mpt_ops, async_created_item): | ||
| item = await async_mpt_vendor.catalog.items.review(async_created_item.id) | ||
| assert item.status == "Pending" | ||
|
|
||
| item = await async_mpt_ops.catalog.items.publish(async_created_item.id) | ||
| assert item.status == "Published" | ||
|
|
||
|
|
||
| async def test_get_item(async_mpt_vendor, item_id): | ||
| service = async_mpt_vendor.catalog.items | ||
| item = await service.get(item_id) | ||
| assert item.id == item_id | ||
|
|
||
|
|
||
| async def test_iterate_items(async_mpt_vendor, async_created_item): | ||
| service = async_mpt_vendor.catalog.items | ||
| items = [item async for item in service.iterate()] | ||
| assert any(item.id == async_created_item.id for item in items) | ||
|
|
||
|
|
||
| async def test_filter(async_mpt_vendor, item_id): | ||
| service = async_mpt_vendor.catalog.items | ||
| items = [item async for item in service.filter(RQLQuery(id=item_id)).iterate()] | ||
| assert len(items) == 1 | ||
| assert items[0].id == item_id | ||
|
|
||
|
|
||
| async def test_not_found(async_mpt_vendor): | ||
| service = async_mpt_vendor.catalog.items | ||
| with pytest.raises(MPTAPIError): | ||
| await service.get("ITM-000-000") | ||
|
|
||
|
|
||
| async def test_delete_item(async_mpt_vendor, async_created_item): | ||
| service = async_mpt_vendor.catalog.items | ||
| await service.delete(async_created_item.id) | ||
| with pytest.raises(MPTAPIError): | ||
| await service.get(async_created_item.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,69 @@ | ||
| 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 created_item(logger, mpt_vendor, item_data): | ||
| service = mpt_vendor.catalog.items | ||
| item = service.create(item_data) | ||
| yield item | ||
| try: | ||
| service.delete(item.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete item {item.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| def test_create_item(created_item): | ||
| assert created_item.name == "e2e - please delete" | ||
|
|
||
|
|
||
| def test_update_item(mpt_vendor, created_item): | ||
| service = mpt_vendor.catalog.items | ||
| update_data = {"name": "please delete me"} | ||
| item = service.update(created_item.id, update_data) | ||
| assert item.name == "please delete me" | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Leaves test items in the catalog") | ||
| def test_review_and_publish_item(mpt_vendor, mpt_ops, created_item): | ||
| item = mpt_vendor.catalog.items.review(created_item.id) | ||
| assert item.status == "Pending" | ||
|
|
||
| item = mpt_ops.catalog.items.publish(created_item.id) | ||
| assert item.status == "Published" | ||
|
|
||
|
|
||
| def test_get_item(mpt_vendor, item_id): | ||
| service = mpt_vendor.catalog.items | ||
| item = service.get(item_id) | ||
| assert item.id == item_id | ||
|
|
||
|
|
||
| def test_iterate_items(mpt_vendor, created_item): | ||
| service = mpt_vendor.catalog.items | ||
| items = list(service.iterate()) | ||
| assert any(item.id == created_item.id for item in items) | ||
|
|
||
|
|
||
| def test_filter(mpt_vendor, item_id): | ||
| service = mpt_vendor.catalog.items | ||
| items = list(service.filter(RQLQuery(id=item_id)).iterate()) | ||
| assert len(items) == 1 | ||
| assert items[0].id == item_id | ||
|
|
||
|
|
||
| def test_not_found(mpt_vendor): | ||
| service = mpt_vendor.catalog.items | ||
| with pytest.raises(MPTAPIError): | ||
| service.get("ITM-000-000") | ||
|
|
||
|
|
||
| def test_delete_item(mpt_vendor, created_item): | ||
| service = mpt_vendor.catalog.items | ||
| service.delete(created_item.id) | ||
| with pytest.raises(MPTAPIError): | ||
| service.get(created_item.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
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.
We could and we do it some times, although this goes against the Requirement 2 of the TDR:
https://softwareone.atlassian.net/wiki/spaces/mpt/pages/6688604176/TDR+Python+API+Client+E2E+Test#Requirements
For now we try to minimise the request done to the API for performance purposes.
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.
No, forget it. I had a look, and with the current implementation it would make little sense. This is why I deleted my message. Thanks!