Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not push runs without seats to ecommerce in data loader #4474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 @@ 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()

run = runs[0]
run.end = datetime.datetime.now(pytz.UTC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is end date set to now here? Where are we checking the seat non-existence here?

run.save()

# Verify the CourseRuns were created correctly
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
Loading