Skip to content

Commit bda7ebe

Browse files
authored
Update search index after updating next_start_date (#2639)
1 parent dbcb98d commit bda7ebe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

learning_resources/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
html_to_markdown,
3434
load_course_blocklist,
3535
resource_unpublished_actions,
36+
resource_upserted_actions,
3637
)
3738
from learning_resources_search.constants import COURSE_TYPE
3839
from learning_resources_search.exceptions import RetryError
@@ -79,6 +80,8 @@ def update_next_start_date_and_prices():
7980
resources = LearningResource.objects.filter(next_start_date__lt=timezone.now())
8081
for resource in resources:
8182
load_run_dependent_values(resource)
83+
if resource.published:
84+
resource_upserted_actions(resource, percolate=False)
8285
clear_search_cache()
8386
return len(resources)
8487

learning_resources/tasks_test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,26 @@ def test_get_youtube_transcripts(mocker):
475475
)
476476

477477

478-
def test_update_next_start_date(mocker):
478+
@pytest.mark.parametrize("published", [True, False])
479+
def test_update_next_start_date(mocker, published):
479480
learning_resource = LearningResourceFactory.create(
480-
next_start_date=(timezone.now() - timedelta(10))
481+
next_start_date=(timezone.now() - timedelta(10)),
482+
published=published,
481483
)
482484
LearningResourceFactory.create(next_start_date=(timezone.now() + timedelta(1)))
483485

484486
mock_load_next_start_date = mocker.patch(
485487
"learning_resources.tasks.load_run_dependent_values"
486488
)
489+
mock_upsert_index = mocker.patch(
490+
"learning_resources.tasks.resource_upserted_actions"
491+
)
487492
update_next_start_date_and_prices()
488493
mock_load_next_start_date.assert_called_once_with(learning_resource)
494+
if published:
495+
mock_upsert_index.assert_called_once_with(learning_resource, percolate=False)
496+
else:
497+
mock_upsert_index.assert_not_called()
489498

490499

491500
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)