Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use LearnerLicenseSerializer for auto-apply API #610

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions license_manager/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1411,8 +1411,19 @@ def test_auto_apply_200_if_successful(
self._setup_request_jwt(user=self.super_user)
response = self.api_client.post(self.auto_apply_url)
assert response.status_code == status.HTTP_200_OK
assert response.json()['user_email'] == self.super_user.email
assert response.json()['status'] == 'activated'

response_json = response.json()
response_subscription_plan = response_json['subscription_plan']
response_customer_agreement = response_json['customer_agreement']
assert response_json['user_email'] == self.super_user.email
assert response_json['status'] == 'activated'
assert response_json['subscription_plan']['uuid'] == str(plan.uuid)
assert response_subscription_plan['title'] == plan.title
assert response_subscription_plan['enterprise_catalog_uuid'] == str(plan.enterprise_catalog_uuid)
assert response_subscription_plan['is_active'] == plan.is_active
assert response_customer_agreement['uuid'] == str(self.customer_agreement.uuid)
expected_customer_agreement_customer_uuid = str(self.customer_agreement.enterprise_customer_uuid)
assert response_customer_agreement['enterprise_customer_uuid'] == expected_customer_agreement_customer_uuid

# Check if 1 License has become auto_applied
assert plan.licenses.filter(auto_applied=True).count() == 1
Expand Down
9 changes: 6 additions & 3 deletions license_manager/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def _auto_apply_new_license(self, subscription_plan, user_email, lms_user_id):
"""
now = localized_utcnow()

auto_applied_license = subscription_plan.unassigned_licenses.first()
auto_applied_license = subscription_plan.unassigned_licenses.select_related(
'subscription_plan',
'subscription_plan__customer_agreement',
).first()
if not auto_applied_license:
return None

Expand Down Expand Up @@ -219,7 +222,7 @@ def auto_apply(self, request, customer_agreement_uuid=None):
)

# Serialize the License we created to be returned in response
serializer = serializers.LicenseSerializer(license_obj)
serializer = serializers.LearnerLicenseSerializer(license_obj)
response_data = serializer.data
return Response(data=response_data, status=status.HTTP_200_OK)

Expand Down Expand Up @@ -248,7 +251,7 @@ def _check_subscription_licenses(self, customer_agreement, plan, user_email):
logger.info(info_message)

license_obj = active_or_assigned_licenses[0]
serializer = serializers.LicenseSerializer(license_obj)
serializer = serializers.LearnerLicenseSerializer(license_obj)
response_data = serializer.data
return Response(data=response_data, status=status.HTTP_200_OK)

Expand Down
Loading