@@ -116,16 +116,19 @@ def make_studio_data(self, run, add_pacing=True, add_schedule=True, team=None, a
116116 }
117117 if add_pacing :
118118 data ['pacing_type' ] = run .pacing_type
119- if add_schedule :
120- data ['schedule' ] = {
121- 'start' : serialize_datetime (run .start ),
122- 'end' : serialize_datetime (run .end ),
123- }
124- if add_enrollment_dates :
125- data ['schedule' ] = {
126- 'enrollment_start' : serialize_datetime (run .enrollment_start ),
127- 'enrollment_end' : serialize_datetime (run .enrollment_end ),
128- }
119+
120+ if add_schedule or add_enrollment_dates :
121+ data ['schedule' ] = {}
122+ if add_schedule :
123+ data ['schedule' ].update ({
124+ 'start' : serialize_datetime (run .start ),
125+ 'end' : serialize_datetime (run .end ),
126+ })
127+ if add_enrollment_dates :
128+ data ['schedule' ].update ({
129+ 'enrollment_start' : serialize_datetime (run .enrollment_start ),
130+ 'enrollment_end' : serialize_datetime (run .enrollment_end ),
131+ })
129132 return data
130133
131134 def test_create_rerun (self ):
@@ -217,6 +220,32 @@ def test_generate_data_for_studio_api__external_course_missing_enrollment_dates(
217220 f'Enrollment information added to data { output_data } for course run { run .key } '
218221 )
219222
223+ def test_generate_data_for_studio_api__non_external_course_no_start_end_on_update (self ):
224+ """Test that start/end are NOT included when updating a non-external course."""
225+ run = CourseRunFactory () # Default: non-external
226+ expected_data = self .make_studio_data (run , add_pacing = False , add_schedule = False , add_enrollment_dates = True )
227+ with mock .patch ('course_discovery.apps.api.utils.logger' ) as mock_logger :
228+ output_data = StudioAPI .generate_data_for_studio_api (run , creating = False )
229+ self .assertEqual (output_data , expected_data )
230+ mock_logger .info .assert_called_with (
231+ f'Enrollment information added to data { output_data } for course run { run .key } '
232+ )
233+
234+ def test_generate_data_for_studio_api__external_course_start_end_on_update (self ):
235+ """Test that start/end are included for external course on update."""
236+ exec_ed_type = CourseTypeFactory (slug = CourseType .EXECUTIVE_EDUCATION_2U )
237+ run = CourseRunFactory (course = CourseFactory (type = exec_ed_type ))
238+
239+ expected_data = self .make_studio_data (run , add_pacing = False , add_schedule = True , add_enrollment_dates = True )
240+
241+ with mock .patch ('course_discovery.apps.api.utils.logger' ) as mock_logger :
242+ output_data = StudioAPI .generate_data_for_studio_api (run , creating = False )
243+ self .assertEqual (output_data , expected_data )
244+
245+ mock_logger .info .assert_called_with (
246+ f'Enrollment information added to data { output_data } for course run { run .key } '
247+ )
248+
220249 def test_calculate_course_run_key_run_value_with_multiple_runs_per_trimester (self ):
221250 start = datetime .datetime (2017 , 2 , 1 )
222251
0 commit comments