Skip to content

Commit 5d08217

Browse files
authored
feat: add fixed_pricing to ingestion flow (#4397)
1 parent a767229 commit 5d08217

File tree

6 files changed

+23
-4
lines changed

6 files changed

+23
-4
lines changed

course_discovery/apps/course_metadata/data_loaders/csv_loader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ def _create_course_run_api_request_data(self, data, course, course_type, course_
479479
'prices': pricing,
480480
'course': course.key,
481481
}
482+
482483
if rerun:
483484
course_run_creation_fields['rerun'] = rerun
484485
return course_run_creation_fields
@@ -594,6 +595,8 @@ def _update_course_run_request_data(self, data, course_run, course_type, is_draf
594595
f"{data.get('upgrade_deadline_override_time', '')}".strip()
595596
),
596597
}
598+
if fix_price := data.get('fixed_price_usd', ''):
599+
update_course_run_data['fixed_price_usd'] = fix_price
597600

598601
if registration_deadline:
599602
update_course_run_data.update({'enrollment_end': self.get_formatted_datetime_string(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from decimal import Decimal
12
from unittest import mock
23

34
import responses
@@ -329,7 +330,7 @@ class CSVLoaderMixin:
329330
'upgrade_deadline_override_date', 'upgrade_deadline_override_time', 'redirect_url', 'external_identifier',
330331
'lead_capture_form_url', 'organic_url', 'certificate_header', 'certificate_text', 'stat1', 'stat1_text',
331332
'stat2', 'stat2_text', 'organization_logo_override', 'organization_short_code_override', 'variant_id',
332-
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type',
333+
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'fixed_price_usd'
333334
]
334335
# The list of minimal data headers
335336
MINIMAL_CSV_DATA_KEYS_ORDER = [
@@ -389,6 +390,7 @@ class CSVLoaderMixin:
389390
'expected_program_type': 'professional-certificate',
390391
'expected_program_name': 'New Program for all',
391392
'registration_deadline': '2050-01-25T00:00:00+00:00',
393+
"fixed_price_usd": Decimal('123.40'),
392394
}
393395

394396
def setUp(self):
@@ -559,3 +561,4 @@ def _assert_course_run_data(self, course_run, expected_data):
559561
assert sorted(
560562
[language.name for language in course_run.transcript_languages.all()]
561563
) == sorted(expected_data['transcript_language'])
564+
assert course_run.fixed_price_usd == expected_data['fixed_price_usd']

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,8 @@
32333233
"meta_description": "SEO Description",
32343234
"meta_keywords": "Keyword 1, Keyword 2",
32353235
"slug": "",
3236-
'external_course_marketing_type': "short_course"
3236+
'external_course_marketing_type': "short_course",
3237+
"fixed_price_usd": "123.4"
32373238
}
32383239

32393240
VALID_MINIMAL_COURSE_AND_COURSE_RUN_CSV_DICT = {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Unit tests for CSV Data loader.
33
"""
44
import datetime
5+
from decimal import Decimal
56
from tempfile import NamedTemporaryFile
67
from unittest import mock
78

@@ -665,10 +666,11 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
665666
type=self.course_run_type,
666667
status='unpublished',
667668
draft=True,
669+
fixed_price_usd=111.11
668670
)
669671

670672
with NamedTemporaryFile() as csv:
671-
csv = self._write_csv(csv, [mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT])
673+
csv = self._write_csv(csv, [{**mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT, "fixed_price_usd": ""}])
672674
with LogCapture(LOGGER_PATH) as log_capture:
673675
with mock.patch.object(
674676
CSVDataLoader,
@@ -700,7 +702,10 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
700702
course_run = CourseRun.everything.get(course=course, draft=True)
701703

702704
self._assert_course_data(course, self.BASE_EXPECTED_COURSE_DATA)
703-
self._assert_course_run_data(course_run, self.BASE_EXPECTED_COURSE_RUN_DATA)
705+
self._assert_course_run_data(
706+
course_run,
707+
{**self.BASE_EXPECTED_COURSE_RUN_DATA, "fixed_price_usd": Decimal('111.11')}
708+
)
704709

705710
@responses.activate
706711
def test_active_slug(self, jwt_decode_patch): # pylint: disable=unused-argument

course_discovery/apps/course_metadata/management/commands/populate_executive_education_data_csv.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Command(BaseCommand):
4242
'lead_capture_form_url', 'certificate_header', 'certificate_text', 'stat1', 'stat1_text', 'stat2',
4343
'stat2_text', 'organic_url', 'organization_short_code_override', 'organization_logo_override', 'variant_id',
4444
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'restriction_type',
45+
'fixed_price_usd',
4546
]
4647

4748
# Mapping English and Spanish languages to IETF equivalent variants
@@ -362,6 +363,7 @@ def get_transformed_data(self, partially_filled_csv_dict, product_dict):
362363
'what_will_you_learn'
363364
),
364365
'verified_price': partially_filled_csv_dict.get('verified_price') or product_dict['variant']['finalPrice'],
366+
'fixed_price_usd': product_dict['variant'].get('enterprisePriceUsd', ''),
365367
'collaborators': partially_filled_csv_dict.get('collaborators', ''),
366368
"prerequisites": partially_filled_csv_dict.get("prerequisites", ""),
367369
'additional_information': partially_filled_csv_dict.get(

course_discovery/apps/course_metadata/management/commands/tests/test_populate_executive_education_data_csv.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
6363
"startDate": "2022-03-06",
6464
"regCloseDate": "2022-02-06",
6565
"finalRegCloseDate": "2022-02-15",
66+
"enterprisePriceUsd": "333.3"
6667
},
6768
"curriculum": {
6869
"heading": "Course curriculum",
@@ -119,6 +120,7 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
119120
"endDate": "2024-04-28",
120121
"finalRegCloseDate": "2024-03-26",
121122
"websiteVisibility": "private",
123+
"enterprisePriceUsd": 3510.0
122124
}
123125

124126
variant_2 = {
@@ -216,6 +218,7 @@ def test_successful_file_data_population_with_getsmarter_flag_with_multiple_vari
216218
assert data_row['Reg Close Time'] == '00:00:00'
217219
assert data_row['Verified Price'] == str(self.variant_1['finalPrice'])
218220
assert data_row['Restriction Type'] == 'custom-b2b-enterprise'
221+
assert data_row['Fixed Price Usd'] == '3510.0'
219222

220223
data_row = next(reader)
221224
assert data_row['Variant Id'] == self.variant_2['id']
@@ -227,6 +230,7 @@ def test_successful_file_data_population_with_getsmarter_flag_with_multiple_vari
227230
assert data_row['Reg Close Time'] == '00:00:00'
228231
assert data_row['Verified Price'] == str(self.variant_2['finalPrice'])
229232
assert data_row['Restriction Type'] == 'None'
233+
assert data_row['Fixed Price Usd'] == ''
230234

231235
log_capture.check_present(
232236
(
@@ -473,3 +477,4 @@ def _assert_api_response(self, data_row):
473477
assert data_row['Meta Keywords'] == 'Keyword 1, Keyword 2'
474478
assert data_row['Slug'] == 'csv-course-slug'
475479
assert data_row['External Course Marketing Type'] == "short_course"
480+
assert data_row['Fixed Price Usd'] == "333.3"

0 commit comments

Comments
 (0)