Skip to content

Commit

Permalink
fix: deactivating product
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 committed Jan 24, 2025
1 parent 150b8ec commit 53e8099
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 6 additions & 3 deletions courses/sync_external_courses/external_course_sync_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.contrib.contenttypes.models import ContentType
from django.db import transaction
from django.db.models import Subquery
from wagtail.images.models import Image
from wagtail.models import Page

Expand Down Expand Up @@ -832,10 +833,12 @@ def deactivate_removed_course_runs(external_course_run_codes, platform_name):
external_course_run_codes (list): List of external course run codes.
platform_name (str): Name of the platform.
"""
course_runs = CourseRun.objects.filter(
course__platform__name__iexact=platform_name, start_date__gt=now_in_utc()
).exclude(external_course_run_id__in=external_course_run_codes)
course_runs = CourseRun.objects.filter(course__platform__name__iexact=platform_name, start_date__gt=now_in_utc()).exclude(
external_course_run_id__in=external_course_run_codes
)
Product.objects.filter(object_id__in=Subquery(course_runs.values("id"))).update(is_active=False)
course_runs.update(live=False)

log.info(
f"Deactivated {course_runs.count()} course runs for platform {platform_name}."
)
Expand Down
10 changes: 4 additions & 6 deletions courses/sync_external_courses/external_course_sync_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,10 @@ def test_deactivate_removed_course_runs(
"""
platform = PlatformFactory.create(name=EMERITUS_PLATFORM_NAME)
course = CourseFactory.create(platform=platform, is_external=True)
course_run = CourseRunFactory.create(
course=course,
live=True,
external_course_run_id=external_course_run_id,
start_date=start_date,
)
course_run = CourseRunFactory.create(course=course, live=True, external_course_run_id=external_course_run_id, start_date=start_date)
product = ProductFactory.create(content_object=course_run)
deactivate_removed_course_runs(api_course_run_codes, EMERITUS_PLATFORM_NAME)
course_run.refresh_from_db()
product.refresh_from_db()
assert course_run.live == is_live
assert product.is_active == is_live

0 comments on commit 53e8099

Please sign in to comment.