@@ -174,6 +174,72 @@ def test_get_enterprise_customer_data(
174
174
timeout = settings .LMS_CLIENT_TIMEOUT ,
175
175
)
176
176
177
+ @mock .patch ('requests.Response.json' )
178
+ @mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
179
+ def test_create_enterprise_admin_user (self , mock_oauth_client , mock_json ):
180
+ """
181
+ Test that we can use the LmsApiClient to create a new customer admin.
182
+ """
183
+ customer_uuid = str (uuid4 ())
184
+
185
+ mock_created_admin_payload = {
186
+ 'id' : 1 ,
187
+ 'enterprise_customer' : customer_uuid ,
188
+ 'user_email' :
'[email protected] ' ,
189
+ }
190
+ mock_json .return_value = mock_created_admin_payload
191
+
192
+ mock_post = mock_oauth_client .return_value .post
193
+
194
+ mock_post .return_value = requests .Response ()
195
+ mock_post .return_value .status_code = 201
196
+
197
+ client = LmsApiClient ()
198
+ response_payload = client .create_enterprise_admin_user (
199
+ customer_uuid ,
'[email protected] ' ,
200
+ )
201
+
202
+ self .assertEqual (response_payload , mock_created_admin_payload )
203
+ expected_url = 'http://edx-platform.example.com/enterprise/api/v1/pending-enterprise-admin/'
204
+ expected_input = {
205
+ 'enterprise_customer' : customer_uuid ,
206
+ 'user_email' :
'[email protected] ' ,
207
+ }
208
+ mock_post .assert_called_once_with (
209
+ expected_url ,
210
+ json = expected_input ,
211
+ timeout = settings .LMS_CLIENT_TIMEOUT ,
212
+ )
213
+
214
+ @mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
215
+ def test_create_enterprise_admin_error (self , mock_oauth_client ):
216
+ """
217
+ Tests that we raise an exception appropriately when creating a
218
+ new customer admin record with the LmsApiClient().
219
+ """
220
+ customer_uuid = str (uuid4 ())
221
+ mock_post = mock_oauth_client .return_value .post
222
+
223
+ mock_post .side_effect = requests .exceptions .HTTPError ('whoopsie' )
224
+ mock_post .return_value .status_code = 400
225
+
226
+ client = LmsApiClient ()
227
+ with self .assertRaises (requests .exceptions .HTTPError ):
228
+ client .create_enterprise_admin_user (
229
+ customer_uuid ,
'[email protected] ' ,
230
+ )
231
+
232
+ expected_url = 'http://edx-platform.example.com/enterprise/api/v1/pending-enterprise-admin/'
233
+ expected_input = {
234
+ 'enterprise_customer' : customer_uuid ,
235
+ 'user_email' :
'[email protected] ' ,
236
+ }
237
+ mock_post .assert_called_once_with (
238
+ expected_url ,
239
+ json = expected_input ,
240
+ timeout = settings .LMS_CLIENT_TIMEOUT ,
241
+ )
242
+
177
243
@mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
178
244
def test_unlink_users_from_enterprise (self , mock_oauth_client ):
179
245
"""
0 commit comments