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: CSV loader reverting future runs to in LegalReview #4508

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
14 changes: 8 additions & 6 deletions course_discovery/apps/course_metadata/data_loaders/csv_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ def ingest(self): # pylint: disable=too-many-statements
self._register_ingestion_error(CSVIngestionErrors.COURSE_RUN_UPDATE_ERROR, error_message)
continue

if course_run.status == CourseRunStatus.Unpublished:
course_run.refresh_from_db()
# Pushing the run into LegalReview is necessary to ensure that the
# url slug is correctly generated in subdirectory format
course_run.status = CourseRunStatus.LegalReview
course_run.save(update_fields=['status'], send_emails=False)
course_run.refresh_from_db()
Copy link
Contributor Author

@AfaqShuaib09 AfaqShuaib09 Dec 4, 2024

Choose a reason for hiding this comment

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

Moved this refresh_from_db() above to get the updated status and complete the review cycle in one go


if course_run.status in [CourseRunStatus.Unpublished, CourseRunStatus.LegalReview]:
if course_run.status == CourseRunStatus.Unpublished:
# Pushing the run into LegalReview is necessary to ensure that the
# url slug is correctly generated in subdirectory format
course_run.status = CourseRunStatus.LegalReview
course_run.save(update_fields=['status'], send_emails=False)
self._complete_run_review(row, course_run)

logger.info("Course and course run updated successfully for course key {}".format(course_key)) # lint-amnesty, pylint: disable=logging-format-interpolation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

from course_discovery.apps.api.v1.tests.test_views.mixins import APITestCase, OAuth2Mixin
from course_discovery.apps.core.tests.factories import USER_PASSWORD, UserFactory
from course_discovery.apps.course_metadata.choices import ExternalCourseMarketingType, ExternalProductStatus
from course_discovery.apps.course_metadata.choices import (
CourseRunStatus, ExternalCourseMarketingType, ExternalProductStatus
)
from course_discovery.apps.course_metadata.data_loaders.csv_loader import CSVDataLoader
from course_discovery.apps.course_metadata.data_loaders.tests import mock_data
from course_discovery.apps.course_metadata.data_loaders.tests.mixins import CSVLoaderMixin
Expand Down Expand Up @@ -721,6 +723,70 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
{**self.BASE_EXPECTED_COURSE_RUN_DATA, "fixed_price_usd": Decimal('111.11')}
)

@responses.activate
def test_ingest_flow_for_preexisting_course_having_run_in_legal_review_status(
self, jwt_decode_patch
): # pylint: disable=unused-argument
"""
Verify that the course run will be reviewed if csv loader updates data for a course having a run in legal
review status.
"""
self._setup_prerequisites(self.partner)
self.mock_studio_calls(self.partner)
self.mock_ecommerce_publication(self.partner)
self.mock_image_response()

course = CourseFactory(
key=self.COURSE_KEY, partner=self.partner, type=self.course_type, draft=True,
additional_metadata=AdditionalMetadataFactory(taxi_form=None)
)
CourseRunFactory(
course=course,
key=self.COURSE_RUN_KEY,
type=self.course_run_type,
status=CourseRunStatus.LegalReview,
go_live_date=datetime.datetime.now(UTC) - datetime.timedelta(days=5),
draft=True,
fixed_price_usd=111.11
)

with NamedTemporaryFile() as csv:
csv = self._write_csv(csv, [{
**mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT,
}])
with LogCapture(LOGGER_PATH) as log_capture:
with mock.patch.object(
CSVDataLoader,
'_call_course_api',
self.mock_call_course_api
):

loader = CSVDataLoader(self.partner, csv_path=csv.name, product_source=self.source.slug)
loader.ingest()

log_capture.check_present(
(
LOGGER_PATH,
'INFO',
'Course edx+csv_123 is located in the database.'
),
(
LOGGER_PATH,
'INFO',
'Draft flag is set to True for the course CSV Course'
)
)

# Verify the existence of draft and non-draft
assert Course.everything.count() == 2
assert CourseRun.everything.count() == 2

course = Course.everything.get(key=self.COURSE_KEY, partner=self.partner, draft=True)
course_run = CourseRun.everything.get(course=course, draft=True)

self._assert_course_data(course, {**self.BASE_EXPECTED_COURSE_DATA})
assert course_run.status == CourseRunStatus.Published

@responses.activate
def test_active_slug(self, jwt_decode_patch): # pylint: disable=unused-argument
"""
Expand Down
Loading