diff --git a/license_manager/apps/api/v1/tests/test_views.py b/license_manager/apps/api/v1/tests/test_views.py index ecf1397f..a3ccff8b 100644 --- a/license_manager/apps/api/v1/tests/test_views.py +++ b/license_manager/apps/api/v1/tests/test_views.py @@ -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 diff --git a/license_manager/apps/api/v1/views.py b/license_manager/apps/api/v1/views.py index 01a79886..05577207 100644 --- a/license_manager/apps/api/v1/views.py +++ b/license_manager/apps/api/v1/views.py @@ -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 @@ -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) @@ -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)