-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-14884 Catalog product e2e #104
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
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,3 @@ | ||
| { | ||
| "catalog.product.id": "PRD-7255-3950" | ||
| } |
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,13 @@ | ||
| import pathlib | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def product_icon(): | ||
| return pathlib.Path.open(pathlib.Path(__file__).parent / "logo.png", "rb") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def product_data(): | ||
| return {"name": "Test Product", "website": "https://www.example.com"} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,63 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client import RQLQuery | ||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def async_created_product(logger, async_mpt_vendor, product_data, product_icon): | ||
| product = await async_mpt_vendor.catalog.products.create(product_data, icon=product_icon) | ||
|
|
||
| yield product | ||
|
|
||
| try: | ||
| await async_mpt_vendor.catalog.products.delete(product.id) | ||
| except MPTAPIError as error: | ||
| logger.exception("TEARDOWN - Unable to delete product %s: %s", product.id, error.title) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_create_product(async_created_product, product_data): | ||
| assert async_created_product.name == product_data["name"] | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| async def test_update_product(async_mpt_vendor, async_created_product): | ||
| update_data = {"name": "Updated Product"} | ||
|
|
||
| product = await async_mpt_vendor.catalog.products.update(async_created_product.id, update_data) | ||
|
|
||
| assert product.name == update_data["name"] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Leaves test products in the catalog") | ||
| @pytest.mark.flaky | ||
| async def test_product_review_and_publish(async_mpt_vendor, async_mpt_ops, async_created_product): | ||
| await async_mpt_vendor.catalog.products.review(async_created_product.id) | ||
| await async_mpt_ops.catalog.products.publish(async_created_product.id) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| async def test_get_product(async_mpt_vendor, product_id, logger): | ||
| await async_mpt_vendor.catalog.products.get(product_id) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| async def test_product_save_settings(async_mpt_vendor, async_created_product): | ||
| await async_mpt_vendor.catalog.products.update_settings( | ||
| async_created_product.id, {"itemSelection": True} | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| async def test_filter_and_select_products(async_mpt_vendor, product_id): | ||
| select_fields = ["-icon", "-revision", "-settings", "-vendor", "-statistics", "-website"] | ||
|
|
||
| filtered_products = ( | ||
| async_mpt_vendor.catalog.products.filter(RQLQuery(id=product_id)) | ||
| .filter(RQLQuery(name="E2E Seeded")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| products = [product async for product in filtered_products.iterate()] | ||
| assert len(products) == 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,61 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client import RQLQuery | ||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_product(logger, mpt_vendor, product_data, product_icon): | ||
| product = mpt_vendor.catalog.products.create(product_data, icon=product_icon) | ||
|
|
||
| yield product | ||
|
|
||
| try: | ||
| mpt_vendor.catalog.products.delete(product.id) | ||
| except MPTAPIError as error: | ||
| logger.exception("TEARDOWN - Unable to delete product %s: %s", product.id, error.title) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_create_product(created_product, product_data): | ||
| assert created_product.name == product_data["name"] | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_update_product(mpt_vendor, created_product): | ||
| update_data = {"name": "Updated Product"} | ||
|
|
||
| product = mpt_vendor.catalog.products.update(created_product.id, update_data) | ||
|
|
||
| assert product.name == update_data["name"] | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="Leaves test products in the catalog") | ||
| @pytest.mark.flaky | ||
| def test_product_review_and_publish(mpt_vendor, mpt_ops, created_product): | ||
| mpt_vendor.catalog.products.review(created_product.id) | ||
| mpt_ops.catalog.products.publish(created_product.id) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_get_product(mpt_vendor, product_id): | ||
| mpt_vendor.catalog.products.get(product_id) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_product_save_settings(mpt_vendor, created_product): | ||
| mpt_vendor.catalog.products.update_settings(created_product.id, {"itemSelection": True}) | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_filter_and_select_products(mpt_vendor, product_id): | ||
| select_fields = ["-icon", "-revision", "-settings", "-vendor", "-statistics", "-website"] | ||
|
|
||
| filtered_products = ( | ||
| mpt_vendor.catalog.products.filter(RQLQuery(id=product_id)) | ||
| .filter(RQLQuery(name="E2E Seeded")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| products = list(filtered_products.iterate()) | ||
| assert len(products) == 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 |
|---|---|---|
| @@ -1,30 +1,80 @@ | ||
| import json | ||
| import logging | ||
| import os | ||
| import pathlib | ||
|
|
||
| import pytest | ||
| from reportportal_client import RPLogger | ||
|
|
||
| from mpt_api_client import MPTClient | ||
| from mpt_api_client import AsyncMPTClient, MPTClient | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def api_token(): | ||
| return os.getenv("MPT_API_TOKEN") | ||
| def base_url(): | ||
| return os.getenv("MPT_API_BASE_URL") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def base_url(): | ||
| return os.getenv("MPT_API_BASE_URL") | ||
| def mpt_vendor(base_url): | ||
| return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url) # type: ignore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mpt_client(api_token, base_url): | ||
| return MPTClient.from_config(api_token=api_token, base_url=base_url) | ||
| def async_mpt_vendor(base_url): | ||
| return AsyncMPTClient.from_config( | ||
| api_token=os.getenv("MPT_API_TOKEN_VENDOR"), base_url=base_url | ||
| ) # type: ignore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mpt_ops(base_url): | ||
| return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url) # type: ignore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_mpt_ops(base_url): | ||
| return AsyncMPTClient.from_config( | ||
| api_token=os.getenv("MPT_API_TOKEN_OPERATIONS"), base_url=base_url | ||
| ) # type: ignore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mpt_client(base_url): | ||
| return MPTClient.from_config(api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url) # type: ignore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_mpt_client(base_url): | ||
| return AsyncMPTClient.from_config( | ||
| api_token=os.getenv("MPT_API_TOKEN_CLIENT"), base_url=base_url | ||
| ) # type: ignore | ||
|
|
||
| @pytest.fixture(scope="session") | ||
|
|
||
| @pytest.fixture | ||
| def rp_logger(): | ||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.DEBUG) | ||
| logging.setLoggerClass(RPLogger) | ||
| return logger | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def logger(): | ||
| return logging.getLogger("E2E") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def project_root_path(): | ||
| return pathlib.Path(__file__).parent.parent.parent | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def e2e_config(project_root_path): | ||
| filename = os.getenv("TEST_CONFIG_FILE", "e2e_config.test.json") | ||
| file_path = project_root_path.joinpath(filename) | ||
| return json.loads(file_path.read_text()) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def product_id(e2e_config): | ||
| return e2e_config["catalog.product.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,18 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client import MPTClient | ||
| from mpt_api_client.exceptions import MPTAPIError | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_unauthorised(base_url): | ||
| client = MPTClient.from_config(api_token="TKN-invalid", base_url=base_url) # noqa: S106 | ||
|
|
||
| with pytest.raises(MPTAPIError, match=r"401 Unauthorized"): | ||
| client.catalog.products.fetch_page() | ||
|
|
||
|
|
||
| @pytest.mark.flaky | ||
| def test_access(mpt_vendor, product_id): | ||
| product = mpt_vendor.catalog.products.get(product_id) | ||
| assert product.id == product_id |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.