Skip to content

Commit 35ef8e2

Browse files
author
Robert Segal
committed
Added Accounts account by id users endpoints e2e tests
1 parent 9619a7a commit 35ef8e2

File tree

7 files changed

+542
-6
lines changed

7 files changed

+542
-6
lines changed

e2e_config.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"accounts.module.id": "MOD-1756",
1010
"accounts.module.name": "Access Management",
1111
"accounts.seller.id": "SEL-7310-3075",
12+
"accounts.user.id": "USR-9673-3314",
1213
"accounts.user_group.id": "UGR-6822-0561",
1314
"catalog.product.item.id": "ITM-7255-3950-0751",
1415
"catalog.product.document.id": "PDC-7255-3950-0001",

mpt_api_client/resources/accounts/accounts_user_groups.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
from mpt_api_client.http import AsyncService, Service
22
from mpt_api_client.http.mixins import (
33
AsyncCollectionMixin,
4-
AsyncManagedResourceMixin,
4+
AsyncCreateMixin,
5+
AsyncDeleteMixin,
6+
AsyncGetMixin,
57
CollectionMixin,
6-
ManagedResourceMixin,
8+
CreateMixin,
9+
DeleteMixin,
10+
GetMixin,
711
)
812
from mpt_api_client.models import Model
13+
from mpt_api_client.models.model import ResourceData
914

1015

1116
class AccountsUserGroup(Model):
@@ -21,18 +26,48 @@ class AccountsUserGroupsServiceConfig:
2126

2227

2328
class AccountsUserGroupsService(
24-
ManagedResourceMixin[AccountsUserGroup],
29+
GetMixin[AccountsUserGroup],
30+
CreateMixin[AccountsUserGroup],
31+
DeleteMixin,
2532
CollectionMixin[AccountsUserGroup],
2633
Service[AccountsUserGroup],
2734
AccountsUserGroupsServiceConfig,
2835
):
2936
"""Account User Groups Service."""
3037

38+
def update(self, resource_data: ResourceData) -> AccountsUserGroup:
39+
"""Update Account User Group.
40+
41+
Args:
42+
resource_data (ResourceData): Resource data to update.
43+
44+
Returns:
45+
AccountsUserGroup: Updated Account User Group.
46+
"""
47+
response = self.http_client.request("put", self.path, json=resource_data)
48+
49+
return self._model_class.from_response(response)
50+
3151

3252
class AsyncAccountsUserGroupsService(
33-
AsyncManagedResourceMixin[AccountsUserGroup],
53+
AsyncGetMixin[AccountsUserGroup],
54+
AsyncCreateMixin[AccountsUserGroup],
55+
AsyncDeleteMixin,
3456
AsyncCollectionMixin[AccountsUserGroup],
3557
AsyncService[AccountsUserGroup],
3658
AccountsUserGroupsServiceConfig,
3759
):
3860
"""Asynchronous Account User Groups Service."""
61+
62+
async def update(self, resource_data: ResourceData) -> AccountsUserGroup:
63+
"""Update Account User Group.
64+
65+
Args:
66+
resource_data (ResourceData): Resource data to update.
67+
68+
Returns:
69+
AccountsUserGroup: Updated Account User Group.
70+
"""
71+
response = await self.http_client.request("put", self.path, json=resource_data)
72+
73+
return self._model_class.from_response(response)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def invalid_user_id():
6+
return "USR-0000-0000"
7+
8+
9+
@pytest.fixture
10+
def account_user_factory(account_id, user_group_id, uuid_str):
11+
def _account_user( # noqa: WPS430
12+
email: str | None = None, # Must be unique in Marketplace
13+
first_name: str = "E2E Created",
14+
last_name: str = "Account User",
15+
):
16+
if not email:
17+
email = f"e2e_{uuid_str}@dummy.com"
18+
19+
return {
20+
"user": {
21+
"firstName": first_name,
22+
"lastName": last_name,
23+
"email": email,
24+
},
25+
"account": {
26+
"id": account_id,
27+
},
28+
"groups": [
29+
{"id": user_group_id},
30+
],
31+
"invitation": {
32+
"status": "Invited",
33+
},
34+
}
35+
36+
return _account_user
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
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+
def users(mpt_vendor, account_id):
11+
return mpt_vendor.accounts.accounts.users(account_id=account_id) # noqa: WPS204
12+
13+
14+
@pytest.fixture
15+
def created_account_user(mpt_vendor, account_user_factory, account_id):
16+
"""Fixture to create and teardown an account user."""
17+
ret_account_user = None
18+
19+
def _created_account_user(
20+
first_name: str = "E2E Created",
21+
last_name: str = "Account User",
22+
):
23+
"""Create an account user with the given first and last name."""
24+
nonlocal ret_account_user # noqa: WPS420
25+
account_user_data = account_user_factory(
26+
first_name=first_name,
27+
last_name=last_name,
28+
)
29+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
30+
ret_account_user = users_obj.create(account_user_data)
31+
return ret_account_user
32+
33+
yield _created_account_user
34+
35+
if ret_account_user:
36+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
37+
try:
38+
users_obj.delete(ret_account_user.id)
39+
except MPTAPIError:
40+
print( # noqa: WPS421
41+
f"TEARDOWN - Unable to delete account user {ret_account_user.id}",
42+
)
43+
44+
45+
@pytest.fixture
46+
def created_user_group(mpt_ops, user_group_factory):
47+
"""Fixture to create and teardown a user group."""
48+
new_user_group_request_data = user_group_factory()
49+
created_user_group = mpt_ops.accounts.user_groups.create(new_user_group_request_data)
50+
51+
yield created_user_group
52+
53+
try:
54+
mpt_ops.accounts.user_groups.delete(created_user_group.id)
55+
except MPTAPIError as error:
56+
print(f"TEARDOWN - Unable to delete user group: {error.title}") # noqa: WPS421
57+
58+
59+
@pytest.fixture
60+
def created_account_user_group(mpt_vendor, created_account_user, created_user_group, account_id): # noqa: WPS210
61+
"""Fixture to create and teardown an account user group."""
62+
created_account_user_data = created_account_user()
63+
user_group_data = created_user_group
64+
create_user_group_data = {"id": user_group_data.id}
65+
users = mpt_vendor.accounts.accounts.users(account_id=account_id)
66+
created_account_user_group = users.groups(user_id=created_account_user_data.id).create(
67+
create_user_group_data
68+
)
69+
yield created_account_user_group
70+
71+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
72+
try:
73+
users_obj.groups(user_id=created_account_user_data.id).delete(user_group_data.id)
74+
except MPTAPIError as error:
75+
print(f"TEARDOWN - Unable to delete account user group: {error.title}") # noqa: WPS421
76+
77+
78+
def test_get_account_user_by_id(mpt_vendor, user_id, account_id):
79+
"""Test retrieving an account user by ID."""
80+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
81+
82+
result = users_obj.get(user_id)
83+
84+
assert result is not None
85+
86+
87+
def test_list_account_users(mpt_vendor, account_id):
88+
"""Test listing account users."""
89+
limit = 10
90+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
91+
92+
result = users_obj.fetch_page(limit=limit)
93+
94+
assert len(result) > 0
95+
96+
97+
def test_get_account_user_by_id_not_found(mpt_vendor, invalid_user_id, account_id):
98+
"""Test retrieving an account user by invalid ID."""
99+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
100+
101+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
102+
users_obj.get(invalid_user_id)
103+
104+
105+
def test_filter_account_users(mpt_vendor, user_id, account_id):
106+
"""Test filtering account users."""
107+
select_fields = ["-name"]
108+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
109+
filtered_account_users = users_obj.filter(RQLQuery(id=user_id)).select(*select_fields)
110+
111+
result = list(filtered_account_users.iterate())
112+
113+
assert len(result) == 1
114+
115+
116+
def test_create_account_user(created_account_user):
117+
"""Test creating an account user."""
118+
result = created_account_user()
119+
120+
assert result is not None
121+
122+
123+
def test_delete_account_user(mpt_vendor, created_account_user, account_id):
124+
"""Test deleting an account user."""
125+
account_user_data = created_account_user()
126+
127+
result = mpt_vendor.accounts.accounts.users(account_id=account_id)
128+
129+
result.delete(account_user_data.id)
130+
131+
132+
def test_update_account_user(
133+
mpt_vendor,
134+
account_user_factory,
135+
created_account_user,
136+
account_id,
137+
):
138+
"""Test updating an account user."""
139+
account_user_data = created_account_user()
140+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
141+
updated_account_user_data = account_user_factory(
142+
first_name="E2E Updated",
143+
last_name="Account User",
144+
)
145+
146+
result = users_obj.update(
147+
account_user_data.id,
148+
updated_account_user_data,
149+
)
150+
151+
assert result is not None
152+
153+
154+
def test_account_user_resend_invite(
155+
mpt_vendor,
156+
created_account_user,
157+
account_id,
158+
):
159+
"""Test resending an invite to an account user."""
160+
account_user_data = created_account_user()
161+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
162+
163+
result = users_obj.resend_invite(account_user_data.id)
164+
165+
assert result is not None
166+
167+
168+
def test_account_user_group_post(created_account_user_group):
169+
"""Test creating an account user group."""
170+
result = created_account_user_group
171+
172+
assert result is not None
173+
174+
175+
def test_account_user_group_update(
176+
mpt_vendor,
177+
created_account_user,
178+
created_user_group,
179+
account_id,
180+
):
181+
"""Test updating an account user group."""
182+
created_account_user_data = created_account_user()
183+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
184+
update_user_group_data = [{"id": created_user_group.id}]
185+
186+
result = users_obj.groups(user_id=created_account_user_data.id).update(update_user_group_data)
187+
188+
assert result is not None
189+
190+
191+
def test_account_user_group_delete(
192+
mpt_vendor,
193+
created_account_user,
194+
created_user_group,
195+
account_id,
196+
):
197+
"""Test deleting an account user group."""
198+
created_account_user_data = created_account_user()
199+
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
200+
create_user_group_data = {"id": created_user_group.id}
201+
users_obj.groups(user_id=created_account_user_data.id).create(create_user_group_data)
202+
203+
users_obj.groups(user_id=created_account_user_data.id).delete(created_user_group.id) # act

0 commit comments

Comments
 (0)