Skip to content

Commit

Permalink
feat: add fixed_pricing to ingestion flow (#4397)
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila authored Jul 30, 2024
1 parent a767229 commit 5d08217
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def _create_course_run_api_request_data(self, data, course, course_type, course_
'prices': pricing,
'course': course.key,
}

if rerun:
course_run_creation_fields['rerun'] = rerun
return course_run_creation_fields
Expand Down Expand Up @@ -594,6 +595,8 @@ def _update_course_run_request_data(self, data, course_run, course_type, is_draf
f"{data.get('upgrade_deadline_override_time', '')}".strip()
),
}
if fix_price := data.get('fixed_price_usd', ''):
update_course_run_data['fixed_price_usd'] = fix_price

if registration_deadline:
update_course_run_data.update({'enrollment_end': self.get_formatted_datetime_string(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from decimal import Decimal
from unittest import mock

import responses
Expand Down Expand Up @@ -329,7 +330,7 @@ class CSVLoaderMixin:
'upgrade_deadline_override_date', 'upgrade_deadline_override_time', 'redirect_url', 'external_identifier',
'lead_capture_form_url', 'organic_url', 'certificate_header', 'certificate_text', 'stat1', 'stat1_text',
'stat2', 'stat2_text', 'organization_logo_override', 'organization_short_code_override', 'variant_id',
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type',
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'fixed_price_usd'
]
# The list of minimal data headers
MINIMAL_CSV_DATA_KEYS_ORDER = [
Expand Down Expand Up @@ -389,6 +390,7 @@ class CSVLoaderMixin:
'expected_program_type': 'professional-certificate',
'expected_program_name': 'New Program for all',
'registration_deadline': '2050-01-25T00:00:00+00:00',
"fixed_price_usd": Decimal('123.40'),
}

def setUp(self):
Expand Down Expand Up @@ -559,3 +561,4 @@ def _assert_course_run_data(self, course_run, expected_data):
assert sorted(
[language.name for language in course_run.transcript_languages.all()]
) == sorted(expected_data['transcript_language'])
assert course_run.fixed_price_usd == expected_data['fixed_price_usd']
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,8 @@
"meta_description": "SEO Description",
"meta_keywords": "Keyword 1, Keyword 2",
"slug": "",
'external_course_marketing_type': "short_course"
'external_course_marketing_type': "short_course",
"fixed_price_usd": "123.4"
}

VALID_MINIMAL_COURSE_AND_COURSE_RUN_CSV_DICT = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Unit tests for CSV Data loader.
"""
import datetime
from decimal import Decimal
from tempfile import NamedTemporaryFile
from unittest import mock

Expand Down Expand Up @@ -665,10 +666,11 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
type=self.course_run_type,
status='unpublished',
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])
csv = self._write_csv(csv, [{**mock_data.VALID_COURSE_AND_COURSE_RUN_CSV_DICT, "fixed_price_usd": ""}])
with LogCapture(LOGGER_PATH) as log_capture:
with mock.patch.object(
CSVDataLoader,
Expand Down Expand Up @@ -700,7 +702,10 @@ def test_ingest_flow_for_preexisting_unpublished_course(self, jwt_decode_patch):
course_run = CourseRun.everything.get(course=course, draft=True)

self._assert_course_data(course, self.BASE_EXPECTED_COURSE_DATA)
self._assert_course_run_data(course_run, self.BASE_EXPECTED_COURSE_RUN_DATA)
self._assert_course_run_data(
course_run,
{**self.BASE_EXPECTED_COURSE_RUN_DATA, "fixed_price_usd": Decimal('111.11')}
)

@responses.activate
def test_active_slug(self, jwt_decode_patch): # pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Command(BaseCommand):
'lead_capture_form_url', 'certificate_header', 'certificate_text', 'stat1', 'stat1_text', 'stat2',
'stat2_text', 'organic_url', 'organization_short_code_override', 'organization_logo_override', 'variant_id',
'meta_title', 'meta_description', 'meta_keywords', 'slug', 'external_course_marketing_type', 'restriction_type',
'fixed_price_usd',
]

# Mapping English and Spanish languages to IETF equivalent variants
Expand Down Expand Up @@ -362,6 +363,7 @@ def get_transformed_data(self, partially_filled_csv_dict, product_dict):
'what_will_you_learn'
),
'verified_price': partially_filled_csv_dict.get('verified_price') or product_dict['variant']['finalPrice'],
'fixed_price_usd': product_dict['variant'].get('enterprisePriceUsd', ''),
'collaborators': partially_filled_csv_dict.get('collaborators', ''),
"prerequisites": partially_filled_csv_dict.get("prerequisites", ""),
'additional_information': partially_filled_csv_dict.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
"startDate": "2022-03-06",
"regCloseDate": "2022-02-06",
"finalRegCloseDate": "2022-02-15",
"enterprisePriceUsd": "333.3"
},
"curriculum": {
"heading": "Course curriculum",
Expand Down Expand Up @@ -119,6 +120,7 @@ class TestPopulateExecutiveEducationDataCsv(CSVLoaderMixin, TestCase):
"endDate": "2024-04-28",
"finalRegCloseDate": "2024-03-26",
"websiteVisibility": "private",
"enterprisePriceUsd": 3510.0
}

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

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

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

0 comments on commit 5d08217

Please sign in to comment.