Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openedx/license-manager into ENT-…
Browse files Browse the repository at this point in the history
…9206/modify-license-mgr-bulk-revoke-behaviour
  • Loading branch information
hamzawaleed01 committed Sep 10, 2024
2 parents d249767 + 4cb33cc commit 455ab8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Adding new check for github-actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
21 changes: 11 additions & 10 deletions license_manager/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ def test_bulk_revoke_no_valid_subscription_plan_superuser(self, mock_revoke_lice
response = self.api_client.post(request_url, request_payload)

assert response.status_code == status.HTTP_404_NOT_FOUND
expected_response_message = {'error_messages': [
expected_response_message = {'unsuccessful_revocations': [
{'error': 'No SubscriptionPlan identified by {} exists'.format(non_existent_uuid)}]}
self.assertEqual(expected_response_message, response.json())
self.assertFalse(mock_revoke_license.called)
Expand Down Expand Up @@ -3143,7 +3143,8 @@ def test_bulk_revoke_not_enough_revocations_remaining(self, mock_revoke_license)
response = self.api_client.post(request_url, request_payload)

assert response.status_code == status.HTTP_400_BAD_REQUEST
expected_response_message = {'error_messages': [{'error': 'Plan does not have enough revocations remaining.'}]}
expected_response_message = {'unsuccessful_revocations': [
{'error': 'Plan does not have enough revocations remaining.'}]}
self.assertEqual(expected_response_message, response.json())
self.assertFalse(mock_revoke_license.called)

Expand Down Expand Up @@ -3177,15 +3178,15 @@ def test_bulk_revoke_license_not_found(self, mock_revoke_license, mock_execute_p
self.subscription_plan.uuid)
)
response_data = response.json()
self.assertIn('revocation_results', response_data)
self.assertIn('error_messages', response_data)
self.assertIn('successful_revocations', response_data)
self.assertIn('unsuccessful_revocations', response_data)

self.assertEqual(len(response_data['revocation_results']), 1)
self.assertIsInstance(response_data['revocation_results'][0]['user_email'], str)
self.assertEqual(len(response_data['successful_revocations']), 1)
self.assertIsInstance(response_data['successful_revocations'][0]['user_email'], str)

self.assertEqual(len(response_data['error_messages']), 1)
self.assertIsInstance(response_data['error_messages'][0]['user_email'], str)
self.assertEqual(response_data['error_messages'][0]['error'], expected_error_msg)
self.assertEqual(len(response_data['unsuccessful_revocations']), 1)
self.assertIsInstance(response_data['unsuccessful_revocations'][0]['user_email'], str)
self.assertEqual(response_data['unsuccessful_revocations'][0]['error'], expected_error_msg)
mock_revoke_license.assert_called_once_with(alice_license)

@mock.patch('license_manager.apps.api.v1.views.revoke_license')
Expand All @@ -3212,7 +3213,7 @@ def test_bulk_revoke_license_revocation_error(self, mock_revoke_license):
response = self.api_client.post(self.bulk_revoke_license_url, request_payload)

assert response.status_code == status.HTTP_400_BAD_REQUEST
expected_error_msg = {'error_messages': [{
expected_error_msg = {'unsuccessful_revocations': [{
'error': "Action: license revocation failed for license: {} because: {}".format(
alice_license.uuid,
'floor is lava. user_email: [email protected]',
Expand Down
14 changes: 7 additions & 7 deletions license_manager/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,14 +1324,14 @@ def bulk_revoke(self, request, subscription_uuid=None):
Response Body:
{
"revocation_results": [
"successful_revocations": [
{
"license_uuid": "string",
"original_status": "string",
"user_email": "string"
}
],
"error_messages": [
"unsuccessful_revocations": [
{
"error": "string",
"error_response_status": "integer",
Expand Down Expand Up @@ -1365,7 +1365,7 @@ def bulk_revoke(self, request, subscription_uuid=None):
subscription_uuid,
)
return Response({
'error_messages': [
'unsuccessful_revocations': [
{'error': error_message}
]
},
Expand All @@ -1380,7 +1380,7 @@ def bulk_revoke(self, request, subscription_uuid=None):
if len(user_emails) > subscription_plan.num_revocations_remaining:
error_message = 'Plan does not have enough revocations remaining.'
return Response({
'error_messages': [
'unsuccessful_revocations': [
{'error': error_message}
]
}, status=status.HTTP_400_BAD_REQUEST)
Expand Down Expand Up @@ -1410,7 +1410,7 @@ def bulk_revoke(self, request, subscription_uuid=None):
# Case 1: if all revocations failed; return only the error messages list
if error_response_status and not revocation_results:
return Response({
'error_messages': error_messages
'unsuccessful_revocations': error_messages
},
status=error_response_status
)
Expand All @@ -1426,8 +1426,8 @@ def bulk_revoke(self, request, subscription_uuid=None):
'user_email': str(user_email)
})
results = {
'revocation_results': revocation_succeeded,
'error_messages': error_messages
'successful_revocations': revocation_succeeded,
'unsuccessful_revocations': error_messages
}
if not error_messages:
return Response(data=results, status=status.HTTP_200_OK)
Expand Down

0 comments on commit 455ab8a

Please sign in to comment.