Skip to content

Commit ca476f5

Browse files
author
Robert Segal
committed
Added Accounts licensees e2e tests
1 parent 72dac51 commit ca476f5

File tree

7 files changed

+514
-12
lines changed

7 files changed

+514
-12
lines changed

e2e_config.test.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
{
2-
"accounts.seller.id": "SEL-7310-3075",
32
"accounts.account.id": "ACC-9042-0088",
3+
"accounts.api_token.id": "TKN-8857-1729",
44
"accounts.buyer.account.id": "ACC-1086-6867",
55
"accounts.buyer.id": "BUY-1591-2112",
6-
"accounts.user_group.id": "UGR-6822-0561",
6+
"accounts.licensee.account.id": "ACC-1086-6867",
7+
"accounts.licensee.group.id": "UGR-2757-7226",
8+
"accounts.licensee.id": "LCE-5758-4071-6507",
79
"accounts.module.id": "MOD-1756",
810
"accounts.module.name": "Access Management",
11+
"accounts.seller.id": "SEL-7310-3075",
12+
"accounts.user_group.id": "UGR-6822-0561",
13+
"catalog.item.id": "ITM-7255-3950-0001",
14+
"catalog.product.document.id": "PDC-7255-3950-0001",
915
"catalog.product.id": "PRD-7255-3950",
10-
"catalog.product.parameter_group.id": "PGR-7255-3950-0001",
1116
"catalog.product.item_group.id": "IGR-7255-3950-0001",
1217
"catalog.product.parameter.id": "PAR-7255-3950-0016",
13-
"catalog.product.document.id": "PDC-7255-3950-0001",
14-
"catalog.item.id": "ITM-7255-3950-0001",
15-
"catalog.unit.id": "UNT-1229",
16-
"accounts.api_token.id": "TKN-8857-1729"
18+
"catalog.product.parameter_group.id": "PGR-7255-3950-0001",
19+
"catalog.unit.id": "UNT-1229"
1720
}

mpt_api_client/resources/accounts/licensees.py

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
from typing import override
2+
13
from mpt_api_client.http import AsyncService, Service
24
from mpt_api_client.http.mixins import (
35
AsyncCollectionMixin,
4-
AsyncManagedResourceMixin,
6+
AsyncCreateWithIconMixin,
7+
AsyncDeleteMixin,
8+
AsyncGetMixin,
9+
AsyncUpdateWithIconMixin,
510
CollectionMixin,
6-
ManagedResourceMixin,
11+
CreateWithIconMixin,
12+
DeleteMixin,
13+
GetMixin,
14+
UpdateWithIconMixin,
715
)
16+
from mpt_api_client.http.types import FileTypes
817
from mpt_api_client.models import Model
18+
from mpt_api_client.models.model import ResourceData
919
from mpt_api_client.resources.accounts.mixins import AsyncEnablableMixin, EnablableMixin
1020

1121

@@ -22,20 +32,136 @@ class LicenseesServiceConfig:
2232

2333

2434
class LicenseesService(
35+
CreateWithIconMixin[Licensee],
36+
UpdateWithIconMixin[Licensee],
37+
GetMixin[Licensee],
38+
DeleteMixin,
2539
EnablableMixin[Licensee],
26-
ManagedResourceMixin[Licensee],
2740
CollectionMixin[Licensee],
2841
Service[Licensee],
2942
LicenseesServiceConfig,
3043
):
3144
"""Licensees Service."""
3245

46+
@override
47+
def create(
48+
self,
49+
resource_data: ResourceData,
50+
logo: FileTypes,
51+
data_key: str = "licensee",
52+
icon_key: str = "logo",
53+
) -> Licensee:
54+
"""Create a licensee.
55+
56+
Args:
57+
resource_data (ResourceData): Licensee data.
58+
logo: Logo image in jpg, png, GIF, etc.
59+
data_key: The key for the licensee data.
60+
icon_key: The key for the logo image.
61+
62+
Returns:
63+
Licensee: Created licensee
64+
"""
65+
return super().create(
66+
resource_data=resource_data,
67+
icon=logo,
68+
data_key=data_key,
69+
icon_key=icon_key,
70+
)
71+
72+
@override
73+
def update(
74+
self,
75+
resource_id: str,
76+
resource_data: ResourceData,
77+
logo: FileTypes,
78+
data_key: str = "licensee",
79+
icon_key: str = "logo",
80+
) -> Licensee:
81+
"""Update a licensee.
82+
83+
Args:
84+
resource_id (str): Licensee ID.
85+
resource_data (ResourceData): Licensee data.
86+
logo: Logo image in jpg, png, GIF, etc.
87+
data_key: The key for the licensee data.
88+
icon_key: The key for the logo image.
89+
90+
Returns:
91+
Licensee: Updated licensee
92+
"""
93+
return super().update(
94+
resource_id=resource_id,
95+
resource_data=resource_data,
96+
icon=logo,
97+
data_key=data_key,
98+
icon_key=icon_key,
99+
)
100+
33101

34102
class AsyncLicenseesService(
103+
AsyncCreateWithIconMixin[Licensee],
104+
AsyncUpdateWithIconMixin[Licensee],
105+
AsyncGetMixin[Licensee],
106+
AsyncDeleteMixin,
35107
AsyncEnablableMixin[Licensee],
36-
AsyncManagedResourceMixin[Licensee],
37108
AsyncCollectionMixin[Licensee],
38109
AsyncService[Licensee],
39110
LicenseesServiceConfig,
40111
):
41112
"""Async Licensees Service."""
113+
114+
@override
115+
async def create(
116+
self,
117+
resource_data: ResourceData,
118+
logo: FileTypes,
119+
data_key: str = "licensee",
120+
icon_key: str = "logo",
121+
) -> Licensee:
122+
"""Create a licensee.
123+
124+
Args:
125+
resource_data (ResourceData): Licensee data.
126+
logo: Logo image in jpg, png, GIF, etc.
127+
data_key: The key for the licensee data.
128+
icon_key: The key for the logo image.
129+
130+
Returns:
131+
Licensee: Created licensee
132+
"""
133+
return await super().create(
134+
resource_data=resource_data,
135+
icon=logo,
136+
data_key=data_key,
137+
icon_key=icon_key,
138+
)
139+
140+
@override
141+
async def update(
142+
self,
143+
resource_id: str,
144+
resource_data: ResourceData,
145+
logo: FileTypes,
146+
data_key: str = "licensee",
147+
icon_key: str = "logo",
148+
) -> Licensee:
149+
"""Update a licensee.
150+
151+
Args:
152+
resource_id (str): Licensee ID.
153+
resource_data (ResourceData): Licensee data.
154+
logo: Logo image in jpg, png, GIF, etc.
155+
data_key: The key for the licensee data.
156+
icon_key: The key for the logo image.
157+
158+
Returns:
159+
Licensee: Updated licensee
160+
"""
161+
return await super().update(
162+
resource_id=resource_id,
163+
resource_data=resource_data,
164+
icon=logo,
165+
data_key=data_key,
166+
icon_key=icon_key,
167+
)

tests/e2e/accounts/conftest.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ def _buyer(
9494
def user_group_factory(account_id, module_id):
9595
def _user_group(
9696
name: str = "E2E Test Api Client User Group",
97+
user_group_account_id: str = account_id,
9798
):
9899
return {
99100
"name": name,
100-
"account": {"id": account_id},
101+
"account": {"id": user_group_account_id},
101102
"buyers": None,
102103
"logo": "",
103104
"description": "User group for E2E tests",
@@ -122,3 +123,34 @@ def _api_token(
122123
}
123124

124125
return _api_token
126+
127+
128+
@pytest.fixture
129+
def licensee_factory(seller_id, buyer_id, user_group_factory, licensee_account_id):
130+
def _licensee(
131+
name: str = "Test E2E Licensee",
132+
licensee_type: str = "Client",
133+
):
134+
group = user_group_factory(user_group_account_id=licensee_account_id)
135+
136+
return {
137+
"name": name,
138+
"address": {
139+
"addressLine1": "456 Licensee St",
140+
"city": "Los Angeles",
141+
"state": "CA",
142+
"postCode": "67890",
143+
"country": "US",
144+
},
145+
"useBuyerAddress": False,
146+
"seller": {"id": seller_id},
147+
"buyer": {"id": buyer_id},
148+
"account": {"id": licensee_account_id},
149+
"eligibility": {"client": True, "partner": False},
150+
"groups": [group],
151+
"type": licensee_type,
152+
"status": "Enabled",
153+
"defaultLanguage": "en-US",
154+
}
155+
156+
return _licensee
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
async def async_created_licensee(async_mpt_client, licensee_factory, account_icon):
11+
new_licensee_request_data = licensee_factory(name="E2E Created licensee")
12+
13+
new_licensee = await async_mpt_client.accounts.licensees.create(
14+
new_licensee_request_data, logo=account_icon
15+
)
16+
17+
yield new_licensee
18+
19+
try:
20+
await async_mpt_client.accounts.licensees.delete(new_licensee.id)
21+
except MPTAPIError as error:
22+
print(f"TEARDOWN - Unable to delete licensee: {error.title}") # noqa: WPS421
23+
24+
25+
async def test_get_licensee_by_id(async_mpt_client, licensee_id):
26+
licensee = await async_mpt_client.accounts.licensees.get(licensee_id)
27+
assert licensee is not None
28+
29+
30+
async def test_list_licensees(async_mpt_client):
31+
limit = 10
32+
licensees = await async_mpt_client.accounts.licensees.fetch_page(limit=limit)
33+
assert len(licensees) > 0
34+
35+
36+
async def test_get_licensee_by_id_not_found(async_mpt_client, invalid_licensee_id):
37+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
38+
await async_mpt_client.accounts.licensees.get(invalid_licensee_id)
39+
40+
41+
async def test_filter_licensees(async_mpt_client, licensee_id):
42+
select_fields = ["-address"]
43+
44+
async_filtered_licensees = (
45+
async_mpt_client.accounts.licensees.filter(RQLQuery(id=licensee_id))
46+
.filter(RQLQuery(name="E2E Seeded Licensee"))
47+
.select(*select_fields)
48+
)
49+
50+
licensees = [
51+
filtered_licensee async for filtered_licensee in async_filtered_licensees.iterate()
52+
]
53+
54+
assert len(licensees) == 1
55+
56+
57+
def test_create_licensee(async_created_licensee):
58+
assert async_created_licensee is not None
59+
60+
61+
async def test_delete_licensee(async_mpt_client, async_created_licensee):
62+
await async_mpt_client.accounts.licensees.delete(async_created_licensee.id)
63+
64+
65+
async def test_delete_licensee_not_found(async_mpt_client, invalid_licensee_id):
66+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
67+
await async_mpt_client.accounts.licensees.delete(invalid_licensee_id)
68+
69+
70+
async def test_update_licensee(
71+
async_mpt_client, licensee_factory, account_icon, async_created_licensee
72+
):
73+
updated_licensee_data = licensee_factory(name="E2E Updated Licensee")
74+
75+
updated_licensee = await async_mpt_client.accounts.licensees.update(
76+
async_created_licensee.id, updated_licensee_data, logo=account_icon
77+
)
78+
79+
assert updated_licensee is not None
80+
81+
82+
async def test_update_licensee_not_found(
83+
async_mpt_client, licensee_factory, account_icon, invalid_licensee_id
84+
):
85+
updated_licensee_data = licensee_factory(name="Nonexistent Licensee")
86+
87+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
88+
await async_mpt_client.accounts.licensees.update(
89+
invalid_licensee_id, updated_licensee_data, logo=account_icon
90+
)
91+
92+
93+
async def test_licensee_disable(async_mpt_client, async_created_licensee):
94+
disabled_licensee = await async_mpt_client.accounts.licensees.disable(async_created_licensee.id)
95+
96+
assert disabled_licensee is not None
97+
98+
99+
async def test_licensee_disable_not_found(async_mpt_client, invalid_licensee_id):
100+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
101+
await async_mpt_client.accounts.licensees.disable(invalid_licensee_id)
102+
103+
104+
async def test_licensee_enable(async_mpt_client, async_created_licensee):
105+
await async_mpt_client.accounts.licensees.disable(async_created_licensee.id)
106+
107+
enabled_licensee = await async_mpt_client.accounts.licensees.enable(async_created_licensee.id)
108+
109+
assert enabled_licensee is not None
110+
111+
112+
async def test_licensee_enable_not_found(async_mpt_client, invalid_licensee_id):
113+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
114+
await async_mpt_client.accounts.licensees.enable(invalid_licensee_id)

0 commit comments

Comments
 (0)