def link_learners_to_enterprise_task(learner_emails, enterprise_customer_uuid): """ Links learners to an enterprise asynchronously. Arguments: learner_emails (list): list email addresses to link to the given enterprise. enterprise_customer_uuid (str): UUID (string representation) of the enterprise to link learns to. """ enterprise_api_client = EnterpriseApiClient() for user_email_batch in chunks(learner_emails, PENDING_ACCOUNT_CREATION_BATCH_SIZE): enterprise_api_client.create_pending_enterprise_users( enterprise_customer_uuid, user_email_batch, )
def test_create_pending_enterprise_users_http_error( self, mock_oauth_client): """ Verify the ``create_pending_enterprise_users`` method does not raise an exception for successful requests. """ # Mock out the response from the lms mock_oauth_client.return_value.post.return_value = MockResponse( {'detail': 'Bad Request'}, 400, content=b'error response', ) user_emails = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', ] enterprise_client = EnterpriseApiClient() with self.assertRaises(requests.exceptions.HTTPError): response = enterprise_client.create_pending_enterprise_users( self.uuid, user_emails) mock_oauth_client.return_value.post.assert_called_once_with( enterprise_client.pending_enterprise_learner_endpoint, json=[{ 'enterprise_customer': self.uuid, 'user_email': user_email } for user_email in user_emails], ) assert response.status_code == 400 assert response.content == 'error response'