Skip to content

Commit

Permalink
fix: do not push runs without seats to ecommerce in data loader (#4474)
Browse files Browse the repository at this point in the history
fix: do not push runs without seats to ecommerce in data loader
  • Loading branch information
zawan-ila authored Oct 29, 2024
1 parent 70ff819 commit b556d6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/data_loaders/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def update_course_run(self, official_run, draft_run, body):
self._update_verified_deadline_for_course_run(official_run)
self._update_verified_deadline_for_course_run(draft_run)
has_upgrade_deadline_override = run.seats.filter(upgrade_deadline_override__isnull=False)
if not has_upgrade_deadline_override and official_run:
if not has_upgrade_deadline_override and official_run and official_run.seats.count():
push_to_ecommerce_for_course_run(official_run)

logger.info(f'Processed course run with UUID [{run.uuid}] and key [{run.key}].')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,37 @@ def test_ingest_verified_deadline_with_bypass_end_date_check(self, mock_push_to_
assert original_run1_deadline == updated_run1_upgrade_deadline
assert run3.seats.first().upgrade_deadline is None

@responses.activate
@mock.patch('course_discovery.apps.course_metadata.data_loaders.api.push_to_ecommerce_for_course_run')
def test_not_pushed_to_ecomm_if_no_seats(self, mock_push_to_ecomm):
"""
Verify that LMS data loader will skip pushing a course run to ecommerce
if it has no seats
"""
TieredCache.dangerous_clear_all_tiers()
responses.calls.reset() # pylint: disable=no-member
api_data = self.mock_api()
assert Course.objects.count() == 0
assert CourseRun.objects.count() == 0

self.loader.ingest()
self.assert_api_called(4)
runs = CourseRun.objects.all()

# Change a run's end date to make it different from the one in studio. This
# is needed to trigger the push_to_ecommerce flow in the the loader, which is only
# done in case the end dates differ or a certain waffle flag is set.
run = runs[0]
run.end = datetime.datetime.now(pytz.UTC)
run.save()
assert run.seats.count() == 0

expected_num_course_runs = len(api_data)
assert CourseRun.objects.count() == expected_num_course_runs

self.loader.ingest()
assert not mock_push_to_ecomm.called

@responses.activate
def test_ingest_exception_handling(self):
""" Verify the data loader properly handles exceptions during processing of the data from the API. """
Expand Down

0 comments on commit b556d6f

Please sign in to comment.