@@ -11,38 +11,6 @@ def users(async_mpt_vendor, account_id):
1111 return async_mpt_vendor .accounts .accounts .users (account_id = account_id ) # noqa: WPS204
1212
1313
14- @pytest .fixture
15- async def created_account_user (async_mpt_vendor , account_user_factory , account_id ):
16- """Fixture to create and teardown an account user."""
17- ret_account_user = None
18-
19- async 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 = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
30- ret_account_user = await 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 = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
37- try :
38- await users_obj .delete (ret_account_user .id )
39- except MPTAPIError as error :
40- print ( # noqa: WPS421
41- f"TEARDOWN - Unable to delete account user { ret_account_user .id } : "
42- f"{ getattr (error , 'title' , str (error ))} "
43- )
44-
45-
4614@pytest .fixture
4715async def created_user_group (async_mpt_ops , user_group_factory ):
4816 """Fixture to create and teardown a user group."""
@@ -61,10 +29,10 @@ async def created_user_group(async_mpt_ops, user_group_factory):
6129
6230@pytest .fixture
6331async def created_account_user_group ( # noqa: WPS210
64- async_mpt_vendor , created_account_user , created_user_group , account_id
32+ async_mpt_vendor , async_created_account_user , created_user_group , account_id
6533):
6634 """Fixture to create and teardown an account user group."""
67- created_account_user_data = await created_account_user ()
35+ created_account_user_data = await async_created_account_user ()
6836 user_group_data = created_user_group
6937 create_user_group_data = {"id" : user_group_data .id }
7038 users = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
@@ -85,115 +53,136 @@ async def created_account_user_group( # noqa: WPS210
8553async def test_get_account_user_by_id (async_mpt_vendor , user_id , account_id ):
8654 """Test retrieving an account user by ID."""
8755 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
56+
8857 account_user = await users_obj .get (user_id )
58+
8959 assert account_user is not None
9060
9161
9262async def test_list_account_users (async_mpt_vendor , account_id ):
9363 """Test listing account users."""
9464 limit = 10
95-
9665 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
97- account_users = await users_obj .fetch_page (limit = limit )
9866
99- assert len (account_users ) > 0
67+ result = await users_obj .fetch_page (limit = limit )
68+
69+ assert len (result ) > 0
10070
10171
10272async def test_get_account_user_by_id_not_found (async_mpt_vendor , invalid_user_id , account_id ):
10373 """Test retrieving an account user by invalid ID."""
104- users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
74+ result = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
10575
10676 with pytest .raises (MPTAPIError , match = r"404 Not Found" ):
107- await users_obj .get (invalid_user_id )
77+ await result .get (invalid_user_id )
10878
10979
11080async def test_filter_account_users (async_mpt_vendor , user_id , account_id ):
11181 """Test filtering account users."""
11282 select_fields = ["-name" ]
113-
11483 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
11584 filtered_account_users = users_obj .filter (RQLQuery (id = user_id )).select (* select_fields )
116- account_users = [user async for user in filtered_account_users .iterate ()]
11785
118- assert len ( account_users ) == 1
86+ result = [ user async for user in filtered_account_users . iterate ()]
11987
88+ assert len (result ) == 1
12089
121- async def test_create_account_user (created_account_user ):
90+
91+ async def test_create_account_user (async_created_account_user ):
12292 """Test creating an account user."""
123- account_user_data = await created_account_user ()
124- assert account_user_data is not None
93+ result = await async_created_account_user ()
94+
95+ assert result is not None
12596
12697
127- async def test_delete_account_user (async_mpt_vendor , created_account_user , account_id ):
98+ async def test_delete_account_user (async_mpt_vendor , async_created_account_user , account_id ):
12899 """Test deleting an account user."""
129- account_user_data = await created_account_user ()
130- users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
131- await users_obj .delete (account_user_data .id )
100+ account_user_data = await async_created_account_user ()
101+
102+ result = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
103+
104+ await result .delete (account_user_data .id )
132105
133106
134107async def test_update_account_user (
135108 async_mpt_vendor ,
136109 account_user_factory ,
137- created_account_user ,
110+ async_created_account_user ,
138111 account_id ,
139112):
140113 """Test updating an account user."""
141- account_user_data = await created_account_user ()
114+ account_user_data = await async_created_account_user ()
115+
142116 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
117+
143118 updated_account_user_data = account_user_factory (
144119 first_name = "E2E Updated" ,
145120 last_name = "Account User" ,
146121 )
147- updated_account_user = await users_obj .update (
122+
123+ result = await users_obj .update (
148124 account_user_data .id ,
149125 updated_account_user_data ,
150126 )
151- assert updated_account_user is not None
127+
128+ assert result is not None
152129
153130
154131async def test_account_user_resend_invite (
155132 async_mpt_vendor ,
156- created_account_user ,
133+ async_created_account_user ,
157134 account_id ,
158135):
159136 """Test resending an invite to an account user."""
160- account_user_data = await created_account_user ()
161- users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
162- resend_invite = await users_obj .resend_invite (account_user_data .id )
163- assert resend_invite is not None
137+ account_user_data = await async_created_account_user ()
138+
139+ result = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
140+
141+ result = await result .resend_invite (account_user_data .id )
142+
143+ assert result is not None
164144
165145
166146def test_account_user_group_post (created_account_user_group ): # noqa: AAA01
167147 """Test creating an account user group."""
168- created_account_user_group_data = created_account_user_group
169- assert created_account_user_group_data is not None
148+ result = created_account_user_group
149+
150+ assert result is not None
170151
171152
172153async def test_account_user_group_update (
173154 async_mpt_vendor ,
174- created_account_user ,
155+ async_created_account_user ,
175156 created_user_group ,
176157 account_id ,
177158):
178159 """Test updating an account user group."""
179- created_account_user_data = await created_account_user ()
160+ created_account_user_data = await async_created_account_user ()
161+
180162 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
163+
181164 update_user_group_data = [{"id" : created_user_group .id }]
182- updated_account_user_group = await users_obj .groups (
183- user_id = created_account_user_data .id
184- ).update (update_user_group_data )
185- assert updated_account_user_group is not None
165+
166+ result = await users_obj .groups (user_id = created_account_user_data .id ).update (
167+ update_user_group_data
168+ )
169+
170+ assert result is not None
186171
187172
188173async def test_account_user_group_delete (
189174 async_mpt_vendor ,
190- created_account_user ,
175+ async_created_account_user ,
191176 created_user_group ,
192177 account_id ,
193178):
194179 """Test deleting an account user group."""
195- created_account_user_data = await created_account_user ()
180+ created_account_user_data = await async_created_account_user ()
181+
196182 users_obj = async_mpt_vendor .accounts .accounts .users (account_id = account_id )
183+
197184 create_user_group_data = {"id" : created_user_group .id }
185+
198186 await users_obj .groups (user_id = created_account_user_data .id ).create (create_user_group_data )
187+
199188 await users_obj .groups (user_id = created_account_user_data .id ).delete (created_user_group .id )
0 commit comments