-
Notifications
You must be signed in to change notification settings - Fork 0
[MPT-14865] Added Accounts account by id users endpoints e2e tests #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robcsegal
merged 1 commit into
main
from
MPT-14865-add-e-2-e-tests-for-accounts-users-endpoints
Nov 27, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_user_id(): | ||
| return "USR-0000-0000" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def account_user_factory(account_id, user_group_id, uuid_str): | ||
| def _account_user( # noqa: WPS430 | ||
| email: str | None = None, # Must be unique in Marketplace | ||
| first_name: str = "E2E Created", | ||
| last_name: str = "Account User", | ||
| ): | ||
| if not email: | ||
| email = f"e2e_{uuid_str}@dummy.com" | ||
|
|
||
robcsegal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return { | ||
| "user": { | ||
| "firstName": first_name, | ||
| "lastName": last_name, | ||
| "email": email, | ||
| }, | ||
| "account": { | ||
| "id": account_id, | ||
| }, | ||
| "groups": [ | ||
| {"id": user_group_id}, | ||
| ], | ||
| "invitation": { | ||
| "status": "Invited", | ||
| }, | ||
| } | ||
|
|
||
| return _account_user | ||
199 changes: 199 additions & 0 deletions
199
tests/e2e/accounts/accounts_users/test_async_accounts_users.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| 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 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.""" | ||
| new_user_group_request_data = user_group_factory() | ||
| created_user_group = await async_mpt_ops.accounts.user_groups.create( | ||
| new_user_group_request_data | ||
| ) | ||
|
|
||
| yield created_user_group | ||
|
|
||
| try: | ||
| await async_mpt_ops.accounts.user_groups.delete(created_user_group.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete user group: {getattr(error, 'title', str(error))}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_account_user_group( # noqa: WPS210 | ||
| async_mpt_vendor, 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() | ||
| 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) | ||
| created_account_user_group = await users.groups(user_id=created_account_user_data.id).create( | ||
| create_user_group_data | ||
| ) | ||
| yield created_account_user_group | ||
|
|
||
| users_obj = async_mpt_vendor.accounts.accounts.users(account_id=account_id) | ||
| try: | ||
| await users_obj.groups(user_id=created_account_user_data.id).delete(user_group_data.id) | ||
| except MPTAPIError as error: | ||
| print( # noqa: WPS421 | ||
| f"TEARDOWN - Unable to delete account user group: {getattr(error, 'title', str(error))}" | ||
| ) | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
| 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) | ||
|
|
||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| await users_obj.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 | ||
|
|
||
|
|
||
| async def test_create_account_user(created_account_user): | ||
| """Test creating an account user.""" | ||
| account_user_data = await created_account_user() | ||
| assert account_user_data is not None | ||
|
|
||
|
|
||
| async def test_delete_account_user(async_mpt_vendor, 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) | ||
|
|
||
|
|
||
| async def test_update_account_user( | ||
| async_mpt_vendor, | ||
| account_user_factory, | ||
| created_account_user, | ||
| account_id, | ||
| ): | ||
| """Test updating an account user.""" | ||
| account_user_data = await 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( | ||
| account_user_data.id, | ||
| updated_account_user_data, | ||
| ) | ||
| assert updated_account_user is not None | ||
|
|
||
|
|
||
| async def test_account_user_resend_invite( | ||
| async_mpt_vendor, | ||
| 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 | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
| async def test_account_user_group_update( | ||
| async_mpt_vendor, | ||
| created_account_user, | ||
| created_user_group, | ||
| account_id, | ||
| ): | ||
| """Test updating an account user group.""" | ||
| created_account_user_data = await 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 | ||
|
|
||
|
|
||
| async def test_account_user_group_delete( | ||
| async_mpt_vendor, | ||
| created_account_user, | ||
| created_user_group, | ||
| account_id, | ||
| ): | ||
| """Test deleting an account user group.""" | ||
| created_account_user_data = await 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.