-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: Add fixed_price_usd logic to normalized metadata content price #931
Conversation
49946b7
to
9db81ef
Compare
9db81ef
to
9431fb6
Compare
@extend_schema_field(serializers.FloatField) | ||
def get_content_price(self, obj) -> float: | ||
if obj.is_exec_ed_2u_course: | ||
for entitlement in obj.json_metadata.get('entitlements', []): | ||
if entitlement.get('mode') == CourseMode.PAID_EXECUTIVE_EDUCATION: | ||
return entitlement.get('price') or DEFAULT_NORMALIZED_PRICE | ||
|
||
if not self.advertised_course_run: | ||
def get_content_price(self, obj) -> float: # pylint: disable=unused-argument | ||
if not self.course_run_metadata: | ||
return None | ||
|
||
return self.advertised_course_run.get('first_enrollable_paid_seat_price') or DEFAULT_NORMALIZED_PRICE | ||
if self.course_run_metadata.get('fixed_price_usd'): | ||
return float(self.course_run_metadata.get('fixed_price_usd')) | ||
if self.course.is_exec_ed_2u_course: | ||
for entitlement in self.course_metadata.get('entitlements', []): | ||
if entitlement.get('price') and entitlement.get('mode') == CourseMode.PAID_EXECUTIVE_EDUCATION: | ||
return float(entitlement.get('price')) | ||
if self.course_run_metadata.get('first_enrollable_paid_seat_price'): | ||
return float(self.course_run_metadata.get('first_enrollable_paid_seat_price')) | ||
return DEFAULT_NORMALIZED_PRICE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the introduction of normalized_metadata_by_run was included in #930. Majority of the work in this PR centers around updating get_content_price and adding corresponding tests.
Refactored function to respect expected output type of float
and to handle None
types gracefully as demonstrated by the tests with a deterministic output that can be tested based on the three price fields and their typing:
first_enrollable_paid_seat_price
-int
fixed_price_usd
-str
price
-str
The newly added test for get_content_price
also replicate current typing behavior
9431fb6
to
c9f50e6
Compare
e5856cd
to
8f899bd
Compare
8f899bd
to
a745a52
Compare
Considers a course run's
fixed_price_usd
value as part of theget_content_price
serializer fornormalized_metadata
and upcomingnormalized_metadata_by_run
.PR includes dependent changes from this PR -> #930
Refactors
get_content_price
to respectfloat
type output and to handleNone
type prices gracefully based on the unique incoming data types betweenfirst_enrollable_paid_seat_price
andfixed_price_usd
/price
Adds tests for
get_content_price
for theNormalizedContentMetadataSerializerTests
.Post-review