Skip to content

Commit

Permalink
feat: add fixed_usd_price to CourseRunSerializer and CRUD updates (#4396
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AfaqShuaib09 committed Jul 30, 2024
1 parent 733ad88 commit a767229
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,10 @@ def prefetch_queryset(cls, queryset=None):

class Meta:
model = CourseRun
fields = ('key', 'uuid', 'title', 'external_key', 'image', 'short_description', 'marketing_url',
'seats', 'start', 'end', 'go_live_date', 'enrollment_start', 'enrollment_end', 'weeks_to_complete',
'pacing_type', 'type', 'restriction_type', 'run_type', 'status', 'is_enrollable', 'is_marketable',
'term', 'availability', 'variant_id')
fields = ('key', 'uuid', 'title', 'external_key', 'fixed_price_usd', 'image', 'short_description',
'marketing_url', 'seats', 'start', 'end', 'go_live_date', 'enrollment_start', 'enrollment_end',
'weeks_to_complete', 'pacing_type', 'type', 'restriction_type', 'run_type', 'status', 'is_enrollable',
'is_marketable', 'term', 'availability', 'variant_id')

def get_marketing_url(self, obj):
include_archived = self.context.get('include_archived')
Expand Down
1 change: 1 addition & 0 deletions course_discovery/apps/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ def get_expected_data(cls, course_run, request):
'is_marketable': course_run.is_marketable,
'availability': course_run.availability,
'variant_id': str(course_run.variant_id),
'fixed_price_usd': str(course_run.fixed_price_usd),
'restriction_type': (
course_run.restricted_run.restriction_type
if hasattr(course_run, 'restricted_run')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ def test_create_minimum(self):
'course': ['This field is required.'],
})
variant_id = str(uuid.uuid4())
fixed_price_usd = 500
# Send minimum requested
response = self.client.post(url, {
'course': course.key,
'start': '2000-01-01T00:00:00Z',
'end': '2001-01-01T00:00:00Z',
'run_type': str(self.course_run_type.uuid),
'variant_id': variant_id,
'fixed_price_usd': fixed_price_usd,
}, format='json')
assert response.status_code == 201
new_course_run = CourseRun.everything.get(key=new_key)
Expand All @@ -189,6 +191,7 @@ def test_create_minimum(self):
# default we provide
assert str(new_course_run.end) == '2001-01-01 00:00:00+00:00'
assert str(new_course_run.variant_id) == variant_id
assert new_course_run.fixed_price_usd == round(fixed_price_usd, 2)
# spot check that input made it
assert new_course_run.draft

Expand Down Expand Up @@ -562,13 +565,15 @@ def test_partial_update(self):

expected_min_effort = 867
expected_max_effort = 5309
fixed_price_usd = 500
prev_variant_id = self.draft_course_run.variant_id
variant_id = str(uuid.uuid4())
data = {
'max_effort': expected_max_effort,
'min_effort': expected_min_effort,
'variant_id': variant_id,
'restriction_type': CourseRunRestrictionType.CustomB2BEnterprise.value
'restriction_type': CourseRunRestrictionType.CustomB2BEnterprise.value,
'fixed_price_usd': fixed_price_usd,
}

# Update this course_run with the new info
Expand All @@ -582,6 +587,7 @@ def test_partial_update(self):
assert self.draft_course_run.max_effort == expected_max_effort
assert self.draft_course_run.min_effort == expected_min_effort
assert self.draft_course_run.variant_id == prev_variant_id
assert self.draft_course_run.fixed_price_usd == round(fixed_price_usd, 2)
assert self.draft_course_run.restricted_run == RestrictedCourseRun.everything.get()

def test_partial_update_with_waffle_switch_variant_id_editable_enable(self):
Expand All @@ -594,11 +600,13 @@ def test_partial_update_with_waffle_switch_variant_id_editable_enable(self):

expected_min_effort = 867
expected_max_effort = 5309
fixed_price_usd = 500
variant_id = str(uuid.uuid4())
data = {
'max_effort': expected_max_effort,
'min_effort': expected_min_effort,
'variant_id': variant_id,
'fixed_price_usd': fixed_price_usd,
}

# Update this course_run with the new info
Expand All @@ -612,6 +620,7 @@ def test_partial_update_with_waffle_switch_variant_id_editable_enable(self):
assert self.draft_course_run.max_effort == expected_max_effort
assert self.draft_course_run.min_effort == expected_min_effort
assert str(self.draft_course_run.variant_id) == variant_id
assert self.draft_course_run.fixed_price_usd == round(fixed_price_usd, 2)

def test_partial_update_no_studio_url(self):
""" Verify we skip pushing when no studio url is set. """
Expand Down
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class CourseRunAdmin(SimpleHistoryAdmin):
raw_id_fields = ('course', 'draft_version',)
readonly_fields = [
'enrollment_count', 'recent_enrollment_count', 'hidden', 'key', 'enterprise_subscription_inclusion',
'variant_id'
'variant_id', 'fixed_price_usd'
]
search_fields = ('uuid', 'key', 'title_override', 'course__title', 'slug', 'external_key', 'variant_id')
save_error = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CourseRunDocument(BaseCourseDocument):
end = fields.DateField()
enrollment_start = fields.DateField()
enrollment_end = fields.DateField()
fixed_price_usd = fields.FloatField()
first_enrollable_paid_seat_sku = fields.TextField()
go_live_date = fields.DateField()
has_enrollable_seats = fields.BooleanField()
Expand Down

0 comments on commit a767229

Please sign in to comment.