Skip to content

Commit f716bca

Browse files
feat: academy list copilot comments resolved
1 parent 12c8974 commit f716bca

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

enterprise_access/apps/api/v1/tests/test_customer_billing_ssp_products.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ def test_retrieve_ssp_product_include_pricing_false(
723723

724724
@mock.patch('enterprise_access.apps.api.v1.views.customer_billing.stripe.Price.list')
725725
@mock.patch('enterprise_access.apps.customer_billing.models.get_cached_academy_data')
726-
def test_retrieve_falls_back_to_settings_lookup(self, mock_get_cached_academy_data, mock_price_list):
727-
"""If slug isn't a DB slug, `settings.SSP_PRODUCTS` mapping should allow lookup by lookup_key."""
726+
def test_retrieve_ssp_product_by_slug_when_slug_matches_db(self, mock_get_cached_academy_data, mock_price_list):
727+
"""Retrieve resolves when the path slug matches the DB `slug`."""
728728
# create a product with a known lookup_key
729729
SspProduct.objects.create(
730730
slug='public-mapped-slug',
@@ -736,8 +736,6 @@ def test_retrieve_falls_back_to_settings_lookup(self, mock_get_cached_academy_da
736736
is_active=True,
737737
)
738738

739-
# mapping provided via override_settings decorator
740-
741739
mock_get_cached_academy_data.return_value = {
742740
'title': 'Mapped Academy',
743741
'long_name': 'Mapped Academy Long',

enterprise_access/apps/api/v1/views/customer_billing.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,11 @@ def list(self, request, *args, **kwargs):
344344
},
345345
)
346346
def retrieve(self, request, *args, **kwargs):
347-
# Try normal lookup by slug first. If not found, allow fallback lookup where
348-
# the provided slug corresponds to a configured SSP product key in
349-
# `settings.SSP_PRODUCTS`. In that case, find the SspProduct by its
350-
# configured `lookup_key` so routes like
347+
# Try normal lookup by DB slug first. If not found, attempt fallback resolution where
348+
# the provided path segment might be a Stripe Price lookup_key (or an alias that can be
349+
# resolved to one via Stripe metadata). This supports routes like:
351350
# `/api/v1/ssp-products/essentials_tech_and_digital_transformation/`
352-
# resolve correctly even when the DB `slug` differs.
351+
# even when the DB `slug` differs.
353352
try:
354353
product = self.get_object()
355354
except (exceptions.NotFound, Http404) as exc:
@@ -365,9 +364,8 @@ def retrieve(self, request, *args, **kwargs):
365364
# First, check whether the requested slug actually matches a
366365
# database `stripe_price_lookup_key`. This allows direct lookup_key
367366
# URLs (where slug==lookup_key) to resolve without calling Stripe.
368-
product = SspProduct.objects.filter(
367+
product = self.get_queryset().filter(
369368
stripe_price_lookup_key=requested_slug,
370-
is_active=True,
371369
).first()
372370
logger.debug('DB lookup for stripe_price_lookup_key=%s returned %s', requested_slug, bool(product))
373371

@@ -427,9 +425,8 @@ def retrieve(self, request, *args, **kwargs):
427425
lookup_key_candidate = None
428426

429427
if not product and lookup_key_candidate:
430-
product = SspProduct.objects.filter(
428+
product = self.get_queryset().filter(
431429
stripe_price_lookup_key=lookup_key_candidate,
432-
is_active=True,
433430
).first()
434431

435432
# If no product was resolved via Stripe lookups, raise NotFound.

0 commit comments

Comments
 (0)