Skip to content

Commit

Permalink
fix: don't index courses with anverified upgrade deadline in the past…
Browse files Browse the repository at this point in the history
…. ENT-7394
  • Loading branch information
iloveagent57 committed Jul 11, 2023
1 parent 8b3c9b0 commit 761cb2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion enterprise_catalog/apps/catalog/algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def _should_index_course(course_metadata):
Replicates the B2C index check of whether a certain course should be indexed for search.
A course should only be indexed for algolia search if it has a non-indexed advertiseable course run, at least
one owner, and a marketing url slug.
one owner, a marketing url slug, and the advertisable course run has a verified upgrade deadline in the future
(in the case where there is *no* verified seat, or the upgrade deadline is null, we consider the deadline
to be some arbitrariliy distant date in the future).
The course-discovery check that the course's partner is edX is included by default as the discovery API filters
to the request's site's partner.
The discovery check that the course has an availability level was decided to be a duplicate check that the
Expand All @@ -164,6 +166,10 @@ def _should_index_course(course_metadata):
if not is_course_run_active(advertised_course_run):
return False

upgrade_deadline = _get_verified_upgrade_deadline(advertised_course_run)
if upgrade_deadline < localized_utcnow().timestamp():
return False

owners = course_json_metadata.get('owners') or []
return not advertised_course_run.get('hidden') and len(owners) > 0

Expand Down
27 changes: 27 additions & 0 deletions enterprise_catalog/apps/catalog/tests/test_algolia_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timedelta
from unittest import mock
from uuid import uuid4

Expand All @@ -15,6 +16,7 @@
from enterprise_catalog.apps.catalog.tests.factories import (
ContentMetadataFactory,
)
from enterprise_catalog.apps.catalog.utils import localized_utcnow


ADVERTISED_COURSE_RUN_UUID = uuid4()
Expand All @@ -23,6 +25,11 @@
PAST_COURSE_RUN_UUID_1 = uuid4()


def _fake_upgrade_deadline(days_from_now=0):
deadline = localized_utcnow() + timedelta(days=days_from_now)
return deadline.strftime('%Y-%m-%dT%H:%M:%SZ')


@ddt.ddt
class AlgoliaUtilsTests(TestCase):
"""
Expand All @@ -38,6 +45,24 @@ class AlgoliaUtilsTests(TestCase):
{'expected_result': False, 'is_marketable': False},
{'expected_result': True, },
{'expected_result': True, 'course_run_availability': None},
{
'expected_result': True,
'seats': [
{'type': 'verified', 'upgrade_deadline': _fake_upgrade_deadline(100)}
],
},
{
'expected_result': True,
'seats': [
{'type': 'something-else', 'upgrade_deadline': _fake_upgrade_deadline(-100)}
],
},
{
'expected_result': False,
'seats': [
{'type': 'verified', 'upgrade_deadline': _fake_upgrade_deadline(-1)}
],
},
)
@ddt.unpack
def test_should_index_course(
Expand All @@ -50,6 +75,7 @@ def test_should_index_course(
is_enrollable=True,
is_marketable=True,
course_run_availability='current',
seats=None,
):
"""
Verify that only a course that has a non-hidden advertised course run, at least one owner, and a marketing slug
Expand All @@ -68,6 +94,7 @@ def test_should_index_course(
'is_enrollable': is_enrollable,
'is_marketable': is_marketable,
'availability': course_run_availability,
'seats': seats or [],
},
],
'owners': owners,
Expand Down

0 comments on commit 761cb2a

Please sign in to comment.