Skip to content

Commit

Permalink
fix: serialize only minimal info about a license's customer agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Feb 21, 2024
1 parent 6dd8caf commit 688d048
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 19 additions & 1 deletion license_manager/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ def get_revocations(self, obj):
}


class MinimalCustomerAgreementSerializer(serializers.ModelSerializer):
"""
Minimal serializer for the `CustomerAgreement` model that does not
include information about related subscription plan records.
"""

class Meta:
model = CustomerAgreement
fields = [
'uuid',
'enterprise_customer_uuid',
'enterprise_customer_slug',
'default_enterprise_catalog_uuid',
'disable_expiration_notifications',
'net_days_until_expiration',
]


class CustomerAgreementSerializer(serializers.ModelSerializer):
"""
Serializer for the `CustomerAgreement` model.
Expand Down Expand Up @@ -148,7 +166,7 @@ class LicenseSerializer(serializers.ModelSerializer):
"""

subscription_plan_uuid = serializers.UUIDField(source='subscription_plan_id')
customer_agreement = CustomerAgreementSerializer(source='subscription_plan.customer_agreement')
customer_agreement = MinimalCustomerAgreementSerializer(source='subscription_plan.customer_agreement')

class Meta:
model = License
Expand Down
6 changes: 4 additions & 2 deletions license_manager/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
from rest_framework import status
from rest_framework.test import APIClient

from license_manager.apps.api.serializers import CustomerAgreementSerializer
from license_manager.apps.api.serializers import (
MinimalCustomerAgreementSerializer,
)
from license_manager.apps.api.tests.factories import BulkEnrollmentJobFactory
from license_manager.apps.api.utils import (
acquire_subscription_plan_lock,
Expand Down Expand Up @@ -346,7 +348,7 @@ def _assert_license_response_correct(response, subscription_license):
assert response['activation_key'] == str(subscription_license.activation_key)
assert response['activation_date'] == _iso_8601_format(subscription_license.activation_date)
assert response['last_remind_date'] == _iso_8601_format(subscription_license.last_remind_date)
assert response['customer_agreement'] == CustomerAgreementSerializer(
assert response['customer_agreement'] == MinimalCustomerAgreementSerializer(
subscription_license.subscription_plan.customer_agreement
).data

Expand Down

0 comments on commit 688d048

Please sign in to comment.