Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions e2e_config.test.json
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"
}
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ per-file-ignores =
tests/unit/test_mpt_client.py: WPS235
tests/e2e/accounts/*.py: WPS430 WPS202
tests/e2e/catalog/*.py: WPS421
tests/e2e/catalog/items/*.py: WPS110 WPS202
tests/e2e/catalog/product/documents/*.py: WPS202 WPS421

tests/*:
Expand Down
Empty file added tests/e2e/__init__.py
Empty file.
Empty file added tests/e2e/catalog/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions tests/e2e/catalog/conftest.py
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.
20 changes: 20 additions & 0 deletions tests/e2e/catalog/items/conftest.py
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}"},
}
69 changes: 69 additions & 0 deletions tests/e2e/catalog/items/test_async_item.py
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)"
Copy link
Contributor Author

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

1. E2E tests should check the communication between the client and the real MPT API

2. It shouldn’t test the MPT API itself. Means tests should not check permutations of the cases of the MPT API, and also, it shouldn’t check that MPT creates/updates/deletes entities properly

3. E2E tests should check that simple requests/responses are not failing

For now we try to minimise the request done to the API for performance purposes.

Copy link
Contributor

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!



@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)
69 changes: 69 additions & 0 deletions tests/e2e/catalog/items/test_sync_item.py
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)
6 changes: 6 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import pathlib
import uuid

import pytest
from reportportal_client import RPLogger
Expand Down Expand Up @@ -111,6 +112,11 @@ def invalid_account_id():
return "ACC-0000-0000"


@pytest.fixture
def short_uuid():
return uuid.uuid4().hex[:8]


@pytest.fixture
def invalid_buyer_id():
return "BUY-0000-0000"
Expand Down