Skip to content

Commit b556d6f

Browse files
authored
fix: do not push runs without seats to ecommerce in data loader (#4474)
fix: do not push runs without seats to ecommerce in data loader
1 parent 70ff819 commit b556d6f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

course_discovery/apps/course_metadata/data_loaders/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def update_course_run(self, official_run, draft_run, body):
174174
self._update_verified_deadline_for_course_run(official_run)
175175
self._update_verified_deadline_for_course_run(draft_run)
176176
has_upgrade_deadline_override = run.seats.filter(upgrade_deadline_override__isnull=False)
177-
if not has_upgrade_deadline_override and official_run:
177+
if not has_upgrade_deadline_override and official_run and official_run.seats.count():
178178
push_to_ecommerce_for_course_run(official_run)
179179

180180
logger.info(f'Processed course run with UUID [{run.uuid}] and key [{run.key}].')

course_discovery/apps/course_metadata/data_loaders/tests/test_api.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,37 @@ def test_ingest_verified_deadline_with_bypass_end_date_check(self, mock_push_to_
362362
assert original_run1_deadline == updated_run1_upgrade_deadline
363363
assert run3.seats.first().upgrade_deadline is None
364364

365+
@responses.activate
366+
@mock.patch('course_discovery.apps.course_metadata.data_loaders.api.push_to_ecommerce_for_course_run')
367+
def test_not_pushed_to_ecomm_if_no_seats(self, mock_push_to_ecomm):
368+
"""
369+
Verify that LMS data loader will skip pushing a course run to ecommerce
370+
if it has no seats
371+
"""
372+
TieredCache.dangerous_clear_all_tiers()
373+
responses.calls.reset() # pylint: disable=no-member
374+
api_data = self.mock_api()
375+
assert Course.objects.count() == 0
376+
assert CourseRun.objects.count() == 0
377+
378+
self.loader.ingest()
379+
self.assert_api_called(4)
380+
runs = CourseRun.objects.all()
381+
382+
# Change a run's end date to make it different from the one in studio. This
383+
# is needed to trigger the push_to_ecommerce flow in the the loader, which is only
384+
# done in case the end dates differ or a certain waffle flag is set.
385+
run = runs[0]
386+
run.end = datetime.datetime.now(pytz.UTC)
387+
run.save()
388+
assert run.seats.count() == 0
389+
390+
expected_num_course_runs = len(api_data)
391+
assert CourseRun.objects.count() == expected_num_course_runs
392+
393+
self.loader.ingest()
394+
assert not mock_push_to_ecomm.called
395+
365396
@responses.activate
366397
def test_ingest_exception_handling(self):
367398
""" Verify the data loader properly handles exceptions during processing of the data from the API. """

0 commit comments

Comments
 (0)