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

feat: Add fixed_price_usd logic to normalized metadata content price #931

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Sep 6, 2024

Considers a course run's fixed_price_usd value as part of the get_content_price serializer for normalized_metadata and upcoming normalized_metadata_by_run.

PR includes dependent changes from this PR -> #930

Refactors get_content_price to respect float type output and to handle None type prices gracefully based on the unique incoming data types between first_enrollable_paid_seat_price and fixed_price_usd/price
Adds tests for get_content_price for the NormalizedContentMetadataSerializerTests.

Post-review

  • Squash commits into discrete sets of changes
  • Ensure that once the changes have been deployed to stage, prod is manually deployed

@brobro10000 brobro10000 force-pushed the hu/ent-9029 branch 3 times, most recently from 49946b7 to 9db81ef Compare September 9, 2024 13:43
Comment on lines 139 to 158
@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
Copy link
Member Author

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

@brobro10000 brobro10000 merged commit 3b11df3 into master Oct 8, 2024
4 checks passed
@brobro10000 brobro10000 deleted the hu/ent-9029 branch October 8, 2024 14:52
@brobro10000 brobro10000 mentioned this pull request Oct 8, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants