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
3 changes: 2 additions & 1 deletion e2e_config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"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"
"catalog.unit.id": "UNT-1229",
"accounts.api_token.id": "TKN-8857-1729"
}
20 changes: 11 additions & 9 deletions tests/e2e/accounts/account/test_async_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@pytest.fixture
async def async_created_account(logger, async_mpt_ops, account, account_icon):
account_data = account()
async def async_created_account(logger, async_mpt_ops, account_factory, account_icon):
account_data = account_factory()

res_account = await async_mpt_ops.accounts.accounts.create(account_data, logo=account_icon)

Expand Down Expand Up @@ -41,8 +41,8 @@ def test_create_account(async_created_account):
assert account is not None


async def test_update_account(async_mpt_ops, async_created_account, account, account_icon):
updated_data = account(name="Updated Account Name")
async def test_update_account(async_mpt_ops, async_created_account, account_factory, account_icon):
updated_data = account_factory(name="Updated Account Name")

updated_account = await async_mpt_ops.accounts.accounts.update(
async_created_account.id, updated_data, logo=account_icon
Expand All @@ -52,26 +52,28 @@ async def test_update_account(async_mpt_ops, async_created_account, account, acc


async def test_update_account_invalid_data(
async_mpt_ops, account, async_created_account, account_icon
async_mpt_ops, account_factory, async_created_account, account_icon
):
updated_data = account(name="")
updated_data = account_factory(name="")

with pytest.raises(MPTAPIError, match=r"400 Bad Request"):
await async_mpt_ops.accounts.accounts.update(
async_created_account.id, updated_data, logo=account_icon
)


async def test_update_account_not_found(async_mpt_ops, account, invalid_account_id, account_icon):
non_existent_account = account(name="Non Existent Account")
async def test_update_account_not_found(
async_mpt_ops, account_factory, invalid_account_id, account_icon
):
non_existent_account = account_factory(name="Non Existent Account")

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_ops.accounts.accounts.update(
invalid_account_id, non_existent_account, logo=account_icon
)


async def test_account_enable(async_mpt_ops, account, async_created_account):
async def test_account_enable(async_mpt_ops, account_factory, async_created_account):
await async_mpt_ops.accounts.accounts.disable(async_created_account.id)

account = await async_mpt_ops.accounts.accounts.enable(async_created_account.id)
Expand Down
18 changes: 9 additions & 9 deletions tests/e2e/accounts/account/test_sync_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@pytest.fixture
def created_account(logger, mpt_ops, account, account_icon):
account_data = account()
def created_account(logger, mpt_ops, account_factory, account_icon):
account_data = account_factory()

res_account = mpt_ops.accounts.accounts.create(account_data, logo=account_icon)

Expand Down Expand Up @@ -41,8 +41,8 @@ def test_create_account(created_account):
assert account is not None


def test_update_account(mpt_ops, created_account, account, account_icon):
updated_data = account(name="Updated Account Name")
def test_update_account(mpt_ops, created_account, account_factory, account_icon):
updated_data = account_factory(name="Updated Account Name")

updated_account = mpt_ops.accounts.accounts.update(
created_account.id, updated_data, logo=account_icon
Expand All @@ -51,23 +51,23 @@ def test_update_account(mpt_ops, created_account, account, account_icon):
assert updated_account is not None


def test_update_account_invalid_data(mpt_ops, account, created_account, account_icon):
updated_data = account(name="")
def test_update_account_invalid_data(mpt_ops, account_factory, created_account, account_icon):
updated_data = account_factory(name="")

with pytest.raises(MPTAPIError, match=r"400 Bad Request"):
mpt_ops.accounts.accounts.update(created_account.id, updated_data, logo=account_icon)


def test_update_account_not_found(mpt_ops, account, invalid_account_id, account_icon):
non_existent_account = account(name="Non Existent Account")
def test_update_account_not_found(mpt_ops, account_factory, invalid_account_id, account_icon):
non_existent_account = account_factory(name="Non Existent Account")

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_ops.accounts.accounts.update(
invalid_account_id, non_existent_account, logo=account_icon
)


def test_account_enable(mpt_ops, account, created_account):
def test_account_enable(mpt_ops, account_factory, created_account):
mpt_ops.accounts.accounts.disable(created_account.id)

account = mpt_ops.accounts.accounts.enable(created_account.id)
Expand Down
110 changes: 110 additions & 0 deletions tests/e2e/accounts/api_tokens/test_async_api_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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 created_api_token(async_mpt_vendor, api_token_factory):
new_api_token_request_data = api_token_factory()
created_api_token = await async_mpt_vendor.accounts.api_tokens.create(
new_api_token_request_data
)

yield created_api_token

try:
await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete api token: {error.title}") # noqa: WPS421


async def test_get_api_token_by_id(async_mpt_vendor, api_token_id):
api_token = await async_mpt_vendor.accounts.api_tokens.get(api_token_id)
assert api_token is not None


async def test_list_api_tokens(async_mpt_vendor):
limit = 10
api_tokens = await async_mpt_vendor.accounts.api_tokens.fetch_page(limit=limit)
assert len(api_tokens) > 0


async def test_get_api_token_by_id_not_found(async_mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_vendor.accounts.api_tokens.get(invalid_api_token_id)


async def test_filter_api_tokens(async_mpt_vendor, api_token_id):
select_fields = ["-description"]

filtered_api_tokens = (
async_mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id))
.filter(RQLQuery(name="E2E Seeded Token"))
.select(*select_fields)
)

api_tokens = [filtered_api_token async for filtered_api_token in filtered_api_tokens.iterate()]

assert len(api_tokens) == 1


def test_create_api_token(created_api_token):
new_api_token = created_api_token
assert new_api_token is not None


async def test_delete_api_token(async_mpt_vendor, created_api_token):
await async_mpt_vendor.accounts.api_tokens.delete(created_api_token.id)


async def test_delete_api_token_not_found(async_mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_vendor.accounts.api_tokens.delete(invalid_api_token_id)


async def test_update_api_token(async_mpt_vendor, api_token_factory, created_api_token):
updated_api_token_data = api_token_factory(name="E2E Updated API Token")

updated_api_token = await async_mpt_vendor.accounts.api_tokens.update(
created_api_token.id, updated_api_token_data
)

assert updated_api_token is not None


async def test_update_api_token_not_found(
async_mpt_vendor, api_token_factory, invalid_api_token_id
):
updated_api_token_data = api_token_factory(name="Nonexistent API Token")

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_vendor.accounts.api_tokens.update(
invalid_api_token_id, updated_api_token_data
)


async def test_api_token_disable(async_mpt_vendor, created_api_token):
disabled_api_token = await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id)

assert disabled_api_token is not None


async def test_api_token_disable_not_found(async_mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_vendor.accounts.api_tokens.disable(invalid_api_token_id)


async def test_api_token_enable(async_mpt_vendor, created_api_token):
await async_mpt_vendor.accounts.api_tokens.disable(created_api_token.id)

enabled_api_token = await async_mpt_vendor.accounts.api_tokens.enable(created_api_token.id)

assert enabled_api_token is not None


async def test_api_token_enable_not_found(async_mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_vendor.accounts.api_tokens.enable(invalid_api_token_id)
104 changes: 104 additions & 0 deletions tests/e2e/accounts/api_tokens/test_sync_api_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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_api_token(mpt_vendor, api_token_factory):
new_api_token_request_data = api_token_factory()
created_api_token = mpt_vendor.accounts.api_tokens.create(new_api_token_request_data)

yield created_api_token

try:
mpt_vendor.accounts.api_tokens.delete(created_api_token.id)
except MPTAPIError as error:
print(f"TEARDOWN - Unable to delete api token: {error.title}") # noqa: WPS421


def test_get_api_token_by_id(mpt_vendor, api_token_id):
api_token = mpt_vendor.accounts.api_tokens.get(api_token_id)
assert api_token is not None


def test_list_api_tokens(mpt_vendor):
limit = 10
api_tokens = mpt_vendor.accounts.api_tokens.fetch_page(limit=limit)
assert len(api_tokens) > 0


def test_get_api_token_by_id_not_found(mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_vendor.accounts.api_tokens.get(invalid_api_token_id)


def test_filter_api_tokens(mpt_vendor, api_token_id):
select_fields = ["-name"]

filtered_api_tokens = (
mpt_vendor.accounts.api_tokens.filter(RQLQuery(id=api_token_id))
.filter(RQLQuery(name="E2E Seeded Token"))
.select(*select_fields)
)

api_tokens = list(filtered_api_tokens.iterate())

assert len(api_tokens) == 1


def test_create_api_token(created_api_token):
new_api_token = created_api_token
assert new_api_token is not None


def test_delete_api_token(mpt_vendor, created_api_token):
mpt_vendor.accounts.api_tokens.delete(created_api_token.id)


def test_delete_api_token_not_found(mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_vendor.accounts.api_tokens.delete(invalid_api_token_id)


def test_update_api_token(mpt_vendor, api_token_factory, created_api_token):
updated_api_token_data = api_token_factory(name="E2E Updated API Token")

updated_api_token = mpt_vendor.accounts.api_tokens.update(
created_api_token.id, updated_api_token_data
)

assert updated_api_token is not None


def test_update_api_token_not_found(mpt_vendor, api_token_factory, invalid_api_token_id):
updated_api_token_data = api_token_factory(name="Nonexistent API Token")

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_vendor.accounts.api_tokens.update(invalid_api_token_id, updated_api_token_data)


def test_api_token_disable(mpt_vendor, created_api_token):
disabled_api_token = mpt_vendor.accounts.api_tokens.disable(created_api_token.id)

assert disabled_api_token is not None


def test_api_token_disable_not_found(mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_vendor.accounts.api_tokens.disable(invalid_api_token_id)


def test_api_token_enable(mpt_vendor, created_api_token):
mpt_vendor.accounts.api_tokens.disable(created_api_token.id)

enabled_api_token = mpt_vendor.accounts.api_tokens.enable(created_api_token.id)

assert enabled_api_token is not None


def test_api_token_enable_not_found(mpt_vendor, invalid_api_token_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_vendor.accounts.api_tokens.enable(invalid_api_token_id)
12 changes: 6 additions & 6 deletions tests/e2e/accounts/buyers/test_async_buyers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@pytest.fixture
async def async_created_buyer(async_mpt_ops, buyer, buyer_account_id, account_icon):
new_buyer_request_data = buyer(
async def async_created_buyer(async_mpt_ops, buyer_factory, buyer_account_id, account_icon):
new_buyer_request_data = buyer_factory(
name="E2E Created Buyer",
account_id=buyer_account_id,
)
Expand Down Expand Up @@ -69,9 +69,9 @@ async def test_delete_buyer_not_found(async_mpt_ops, invalid_buyer_id):


async def test_update_buyer(
async_mpt_ops, buyer, buyer_account_id, account_icon, async_created_buyer
async_mpt_ops, buyer_factory, buyer_account_id, account_icon, async_created_buyer
):
updated_buyer_data = buyer(name="E2E Updated Buyer", account_id=buyer_account_id)
updated_buyer_data = buyer_factory(name="E2E Updated Buyer", account_id=buyer_account_id)

updated_buyer = await async_mpt_ops.accounts.buyers.update(
async_created_buyer.id, updated_buyer_data, logo=account_icon
Expand All @@ -81,9 +81,9 @@ async def test_update_buyer(


async def test_update_buyer_not_found(
async_mpt_ops, buyer, buyer_account_id, account_icon, invalid_buyer_id
async_mpt_ops, buyer_factory, buyer_account_id, account_icon, invalid_buyer_id
):
updated_buyer_data = buyer(name="Nonexistent Buyer", account_id=buyer_account_id)
updated_buyer_data = buyer_factory(name="Nonexistent Buyer", account_id=buyer_account_id)

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await async_mpt_ops.accounts.buyers.update(
Expand Down
Loading