Skip to content

Commit

Permalink
Adjust tets and add missing clear_search_cache calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertrand committed Sep 20, 2024
1 parent 30bed3f commit 76542a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
5 changes: 3 additions & 2 deletions learning_resources/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
sync_edx_course_files,
)
from learning_resources.etl.loaders import load_run_dependent_values
from learning_resources.etl.pipelines import ocw_courses_etl
from learning_resources.etl.utils import get_learning_course_bucket_name
from learning_resources.models import LearningResource
from learning_resources.utils import load_course_blocklist
Expand Down Expand Up @@ -88,13 +87,15 @@ def get_oll_data(sheets_id=None):
def get_mitpe_data():
"""Execute the Professional Education ETL pipeline"""
courses, programs = pipelines.mitpe_etl()
clear_search_cache()
return len(courses) + len(programs)


@app.task
def get_sloan_data():
"""Execute the Sloan ETL pipelines"""
courses = pipelines.sloan_courses_etl()
clear_search_cache()
return len(courses)


Expand Down Expand Up @@ -237,7 +238,7 @@ def get_ocw_courses(
)
utc_start_timestamp = utc_start_timestamp.replace(tzinfo=UTC)

ocw_courses_etl(
pipelines.ocw_courses_etl(
url_paths=url_paths,
force_overwrite=force_overwrite,
start_timestamp=utc_start_timestamp,
Expand Down
39 changes: 20 additions & 19 deletions learning_resources/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,31 @@ def mock_blocklist(mocker):

def test_cache_is_cleared_after_task_run(mocker, mocked_celery):
"""Test that the search cache is cleared out after every task run"""
mocker.patch("learning_resources.tasks.ocw_courses_etl", autospec=True)
mocker.patch("learning_resources.tasks.get_content_tasks", autospec=True)
mocker.patch("learning_resources.tasks.pipelines")
mocker.patch("learning_resources.tasks.pipelines.mitpe_etl", return_value=([], []))
mocked_clear_search_cache = mocker.patch(
"learning_resources.tasks.clear_search_cache"
)
tasks.get_mit_edx_data.delay()
tasks.update_next_start_date_and_prices.delay()
tasks.get_micromasters_data.delay()
tasks.get_mit_edx_data.delay()
tasks.get_mitxonline_data.delay()
tasks.get_oll_data.delay()
tasks.get_xpro_data.delay()
tasks.get_podcast_data.delay()

tasks.get_ocw_courses.delay(
url_paths=[OCW_TEST_PREFIX],
force_overwrite=False,
skip_content_files=True,
)

tasks.get_youtube_data.delay()
tasks.get_youtube_transcripts.delay()
assert mocked_clear_search_cache.call_count == 12
tasks_with_kwargs = [
("get_micromasters_data", {}),
("get_mitpe_data", {}),
("get_mit_edx_data", {}),
("get_mitxonline_data", {}),
("get_ocw_courses", {"url_paths": ["foo"], "force_overwrite": True}),
("get_oll_data", {}),
("get_podcast_data", {}),
("get_sloan_data", {}),
("get_xpro_data", {}),
("get_youtube_data", {}),
("get_youtube_transcripts", {}),
("update_next_start_date_and_prices", {}),
]

for task, kwargs in tasks_with_kwargs:
getattr(tasks, task).delay(**kwargs)

assert mocked_clear_search_cache.call_count == len(tasks_with_kwargs)


def test_get_micromasters_data(mocker):
Expand Down

0 comments on commit 76542a7

Please sign in to comment.