Skip to content

Commit

Permalink
feat: serialize available_subscription_catalogs on MinimalCustomerAgr…
Browse files Browse the repository at this point in the history
…eementSerializer (#621)
  • Loading branch information
adamstankiewicz authored Mar 26, 2024
1 parent 404ab86 commit 3b1ab3e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions license_manager/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Meta:
'disable_expiration_notifications',
'net_days_until_expiration',
'subscription_for_auto_applied_licenses',
'available_subscription_catalogs',
]

def get_subscription_for_auto_applied_licenses(self, obj):
Expand Down
11 changes: 11 additions & 0 deletions license_manager/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2724,8 +2724,19 @@ def test_endpoint_results_contains_customer_agreement(self):
response = self._get_url_with_customer_uuid(self.enterprise_customer_uuid)

assert response.status_code == status.HTTP_200_OK

customer_agreement_response = response.json().get('customer_agreement')
expected_days_until_expiration = self.customer_agreement.net_days_until_expiration
expected_disable_expire_notifications = self.customer_agreement.disable_expiration_notifications
assert customer_agreement_response['uuid'] == str(self.customer_agreement.uuid)
assert customer_agreement_response['net_days_until_expiration'] == expected_days_until_expiration
assert customer_agreement_response['disable_expiration_notifications'] == expected_disable_expire_notifications
assert customer_agreement_response['subscription_for_auto_applied_licenses'] is None

expected_available_catalog_uuids = [
str(self.customer_agreement.subscriptions.first().enterprise_catalog_uuid)
]
assert customer_agreement_response['available_subscription_catalogs'] == expected_available_catalog_uuids

def test_endpoint_results_correctly_ordered(self):
"""
Expand Down
17 changes: 17 additions & 0 deletions license_manager/apps/subscriptions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def net_days_until_expiration(self):
net_days = max(net_days, plan.days_until_expiration_including_renewals)
return net_days

@property
def available_subscription_catalogs(self):
"""
Returns all the enterprise catalogs associated with the subscription plans
in this customer agreement.
"""
default_catalog_uuid = self.default_enterprise_catalog_uuid
available_catalog_uuids = set()
for plan in self.subscriptions.filter(is_active=True).prefetch_related('renewal'):
if plan.days_until_expiration_including_renewals > 0:
available_catalog_uuids.add(
str(plan.enterprise_catalog_uuid)
if plan.enterprise_catalog_uuid
else str(default_catalog_uuid)
)
return list(available_catalog_uuids)

@property
def auto_applicable_subscription(self):
"""
Expand Down

0 comments on commit 3b1ab3e

Please sign in to comment.