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
10 changes: 6 additions & 4 deletions mpt_api_client/resources/accounts/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
AsyncCollectionMixin,
AsyncDeleteMixin,
AsyncGetMixin,
AsyncUpdateMixin,
AsyncUpdateFileMixin,
CollectionMixin,
DeleteMixin,
GetMixin,
UpdateMixin,
UpdateFileMixin,
)
from mpt_api_client.models import Model
from mpt_api_client.models.model import ResourceData
Expand All @@ -27,10 +27,12 @@ class UsersServiceConfig:
_endpoint = "/public/v1/accounts/users"
_model_class = User
_collection_key = "data"
_upload_file_key = "icon"
_upload_data_key = "user"


class UsersService(
UpdateMixin[User],
UpdateFileMixin[User],
DeleteMixin,
BlockableMixin[User],
GetMixin[User],
Expand Down Expand Up @@ -71,7 +73,7 @@ def set_password(self, resource_id: str, password: str) -> User:


class AsyncUsersService(
AsyncUpdateMixin[User],
AsyncUpdateFileMixin[User],
AsyncDeleteMixin,
AsyncBlockableMixin[User],
AsyncGetMixin[User],
Expand Down
36 changes: 0 additions & 36 deletions tests/e2e/accounts/accounts_users/conftest.py

This file was deleted.

125 changes: 57 additions & 68 deletions tests/e2e/accounts/accounts_users/test_async_accounts_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,6 @@ def users(async_mpt_vendor, account_id):
return async_mpt_vendor.accounts.accounts.users(account_id=account_id) # noqa: WPS204


@pytest.fixture
async def created_account_user(async_mpt_vendor, account_user_factory, account_id):
"""Fixture to create and teardown an account user."""
ret_account_user = None

async def _created_account_user(
first_name: str = "E2E Created",
last_name: str = "Account User",
):
"""Create an account user with the given first and last name."""
nonlocal ret_account_user # noqa: WPS420
account_user_data = account_user_factory(
first_name=first_name,
last_name=last_name,
)
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
ret_account_user = await users_obj.create(account_user_data)
return ret_account_user

yield _created_account_user

if ret_account_user:
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
try:
await users_obj.delete(ret_account_user.id)
except MPTAPIError as error:
print( # noqa: WPS421
f"TEARDOWN - Unable to delete account user {ret_account_user.id}: "
f"{getattr(error, 'title', str(error))}"
)


@pytest.fixture
async def created_user_group(async_mpt_ops, user_group_factory):
"""Fixture to create and teardown a user group."""
Expand All @@ -61,10 +29,10 @@ async def created_user_group(async_mpt_ops, user_group_factory):

@pytest.fixture
async def created_account_user_group( # noqa: WPS210
async_mpt_vendor, created_account_user, created_user_group, account_id
async_mpt_vendor, async_created_account_user, created_user_group, account_id
):
"""Fixture to create and teardown an account user group."""
created_account_user_data = await created_account_user()
created_account_user_data = await async_created_account_user()
user_group_data = created_user_group
create_user_group_data = {"id": user_group_data.id}
users = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
Expand All @@ -85,115 +53,136 @@ async def created_account_user_group( # noqa: WPS210
async def test_get_account_user_by_id(async_mpt_vendor, user_id, account_id):
"""Test retrieving an account user by ID."""
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

account_user = await users_obj.get(user_id)

assert account_user is not None


async def test_list_account_users(async_mpt_vendor, account_id):
"""Test listing account users."""
limit = 10

users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
account_users = await users_obj.fetch_page(limit=limit)

assert len(account_users) > 0
result = await users_obj.fetch_page(limit=limit)

assert len(result) > 0


async def test_get_account_user_by_id_not_found(async_mpt_vendor, invalid_user_id, account_id):
"""Test retrieving an account user by invalid ID."""
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
result = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

with pytest.raises(MPTAPIError, match=r"404 Not Found"):
await users_obj.get(invalid_user_id)
await result.get(invalid_user_id)


async def test_filter_account_users(async_mpt_vendor, user_id, account_id):
"""Test filtering account users."""
select_fields = ["-name"]

users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
filtered_account_users = users_obj.filter(RQLQuery(id=user_id)).select(*select_fields)
account_users = [user async for user in filtered_account_users.iterate()]

assert len(account_users) == 1
result = [user async for user in filtered_account_users.iterate()]

assert len(result) == 1

async def test_create_account_user(created_account_user):

async def test_create_account_user(async_created_account_user):
"""Test creating an account user."""
account_user_data = await created_account_user()
assert account_user_data is not None
result = await async_created_account_user()

assert result is not None


async def test_delete_account_user(async_mpt_vendor, created_account_user, account_id):
async def test_delete_account_user(async_mpt_vendor, async_created_account_user, account_id):
"""Test deleting an account user."""
account_user_data = await created_account_user()
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
await users_obj.delete(account_user_data.id)
account_user_data = await async_created_account_user()

result = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

await result.delete(account_user_data.id)


async def test_update_account_user(
async_mpt_vendor,
account_user_factory,
created_account_user,
async_created_account_user,
account_id,
):
"""Test updating an account user."""
account_user_data = await created_account_user()
account_user_data = await async_created_account_user()

users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

updated_account_user_data = account_user_factory(
first_name="E2E Updated",
last_name="Account User",
)
updated_account_user = await users_obj.update(

result = await users_obj.update(
account_user_data.id,
updated_account_user_data,
)
assert updated_account_user is not None

assert result is not None


async def test_account_user_resend_invite(
async_mpt_vendor,
created_account_user,
async_created_account_user,
account_id,
):
"""Test resending an invite to an account user."""
account_user_data = await created_account_user()
users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)
resend_invite = await users_obj.resend_invite(account_user_data.id)
assert resend_invite is not None
account_user_data = await async_created_account_user()

result = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

result = await result.resend_invite(account_user_data.id)

assert result is not None


def test_account_user_group_post(created_account_user_group): # noqa: AAA01
"""Test creating an account user group."""
created_account_user_group_data = created_account_user_group
assert created_account_user_group_data is not None
result = created_account_user_group

assert result is not None


async def test_account_user_group_update(
async_mpt_vendor,
created_account_user,
async_created_account_user,
created_user_group,
account_id,
):
"""Test updating an account user group."""
created_account_user_data = await created_account_user()
created_account_user_data = await async_created_account_user()

users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

update_user_group_data = [{"id": created_user_group.id}]
updated_account_user_group = await users_obj.groups(
user_id=created_account_user_data.id
).update(update_user_group_data)
assert updated_account_user_group is not None

result = await users_obj.groups(user_id=created_account_user_data.id).update(
update_user_group_data
)

assert result is not None


async def test_account_user_group_delete(
async_mpt_vendor,
created_account_user,
async_created_account_user,
created_user_group,
account_id,
):
"""Test deleting an account user group."""
created_account_user_data = await created_account_user()
created_account_user_data = await async_created_account_user()

users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id)

create_user_group_data = {"id": created_user_group.id}

await users_obj.groups(user_id=created_account_user_data.id).create(create_user_group_data)

await users_obj.groups(user_id=created_account_user_data.id).delete(created_user_group.id)
31 changes: 0 additions & 31 deletions tests/e2e/accounts/accounts_users/test_sync_accounts_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,6 @@ def users(mpt_vendor, account_id):
return mpt_vendor.accounts.accounts.users(account_id=account_id) # noqa: WPS204


@pytest.fixture
def created_account_user(mpt_vendor, account_user_factory, account_id):
"""Fixture to create and teardown an account user."""
ret_account_user = None

def _created_account_user(
first_name: str = "E2E Created",
last_name: str = "Account User",
):
"""Create an account user with the given first and last name."""
nonlocal ret_account_user # noqa: WPS420
account_user_data = account_user_factory(
first_name=first_name,
last_name=last_name,
)
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
ret_account_user = users_obj.create(account_user_data)
return ret_account_user

yield _created_account_user

if ret_account_user:
users_obj = mpt_vendor.accounts.accounts.users(account_id=account_id)
try:
users_obj.delete(ret_account_user.id)
except MPTAPIError:
print( # noqa: WPS421
f"TEARDOWN - Unable to delete account user {ret_account_user.id}",
)


@pytest.fixture
def created_user_group(mpt_ops, user_group_factory):
"""Fixture to create and teardown a user group."""
Expand Down
Loading