@@ -201,6 +201,7 @@ def test_create_enterprise_customer_data(self, mock_oauth_client, mock_json):
201
201
mock_post .return_value .status_code = 201
202
202
203
203
client = LmsApiClient ()
204
+
204
205
response_payload = client .create_enterprise_customer (** customer_input )
205
206
206
207
self .assertEqual (response_payload , mock_created_customer_payload )
@@ -215,6 +216,43 @@ def test_create_enterprise_customer_data(self, mock_oauth_client, mock_json):
215
216
timeout = settings .LMS_CLIENT_TIMEOUT ,
216
217
)
217
218
219
+ @mock .patch ('requests.Response.json' )
220
+ @mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
221
+ def test_create_enterprise_admin_user (self , mock_oauth_client , mock_json ):
222
+ """
223
+ Test that we can use the LmsApiClient to create a new customer admin.
224
+ """
225
+ customer_uuid = str (uuid4 ())
226
+
227
+ mock_created_admin_payload = {
228
+ 'id' : 1 ,
229
+ 'enterprise_customer' : customer_uuid ,
230
+ 'user_email' :
'[email protected] ' ,
231
+ }
232
+ mock_json .return_value = mock_created_admin_payload
233
+
234
+ mock_post = mock_oauth_client .return_value .post
235
+
236
+ mock_post .return_value = requests .Response ()
237
+ mock_post .return_value .status_code = 201
238
+
239
+ client = LmsApiClient ()
240
+ response_payload = client .create_enterprise_admin_user (
241
+ customer_uuid ,
'[email protected] ' ,
242
+ )
243
+
244
+ self .assertEqual (response_payload , mock_created_admin_payload )
245
+ expected_url = 'http://edx-platform.example.com/enterprise/api/v1/pending-enterprise-admin/'
246
+ expected_input = {
247
+ 'enterprise_customer' : customer_uuid ,
248
+ 'user_email' :
'[email protected] ' ,
249
+ }
250
+ mock_post .assert_called_once_with (
251
+ expected_url ,
252
+ json = expected_input ,
253
+ timeout = settings .LMS_CLIENT_TIMEOUT ,
254
+ )
255
+
218
256
@mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
219
257
def test_create_enterprise_customer_error (self , mock_oauth_client ):
220
258
"""
@@ -249,6 +287,35 @@ def test_create_enterprise_customer_error(self, mock_oauth_client):
249
287
timeout = settings .LMS_CLIENT_TIMEOUT ,
250
288
)
251
289
290
+ @mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
291
+ def test_create_enterprise_admin_error (self , mock_oauth_client ):
292
+ """
293
+ Tests that we raise an exception appropriately when creating a
294
+ new customer admin record with the LmsApiClient().
295
+ """
296
+ customer_uuid = str (uuid4 ())
297
+ mock_post = mock_oauth_client .return_value .post
298
+
299
+ mock_post .side_effect = requests .exceptions .HTTPError ('whoopsie' )
300
+ mock_post .return_value .status_code = 400
301
+
302
+ client = LmsApiClient ()
303
+ with self .assertRaises (requests .exceptions .HTTPError ):
304
+ client .create_enterprise_admin_user (
305
+ customer_uuid ,
'[email protected] ' ,
306
+ )
307
+
308
+ expected_url = 'http://edx-platform.example.com/enterprise/api/v1/pending-enterprise-admin/'
309
+ expected_input = {
310
+ 'enterprise_customer' : customer_uuid ,
311
+ 'user_email' :
'[email protected] ' ,
312
+ }
313
+ mock_post .assert_called_once_with (
314
+ expected_url ,
315
+ json = expected_input ,
316
+ timeout = settings .LMS_CLIENT_TIMEOUT ,
317
+ )
318
+
252
319
@mock .patch ('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient' )
253
320
def test_unlink_users_from_enterprise (self , mock_oauth_client ):
254
321
"""
0 commit comments