Skip to content

Commit

Permalink
refactor: make course mode logic dynamic
Browse files Browse the repository at this point in the history
Description:
Make Fulfillment logic dynamic to support all course modes
SONIC-732
  • Loading branch information
Ahtesham Quraish committed Nov 6, 2024
1 parent 8cba004 commit 0c2dddc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions commerce_coordinator/apps/commercetools/catalog_info/edx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def is_edx_lms_order(order: CTOrder) -> bool:
return len(get_edx_items(order)) >= 1


def get_course_mode_from_ct_order(order: CTOrder) -> str:
mode = 'verified'
for line_item in order.line_items:
for attribute in line_item.variant.attributes:
if attribute.name == 'mode':
mode = attribute.value

return mode


def get_edx_lms_user_id(customer: CTCustomer):
return customer.custom.fields[EdXFieldNames.LMS_USER_ID]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_edx_is_sanctioned,
get_edx_items,
get_edx_lms_user_id,
get_course_mode_from_ct_order,
get_edx_lms_user_name,
get_edx_order_workflow_state_key,
get_edx_payment_intent_id,
Expand Down Expand Up @@ -83,7 +84,7 @@ def fulfill_order_placed_message_signal_task(
'order_id': order.id,
'provider_id': None,
'edx_lms_user_id': lms_user_id,
'course_mode': 'verified',
'course_mode': get_course_mode_from_ct_order(order=order),
'date_placed': order.last_modified_at.strftime(ISO_8601_FORMAT),
'source_system': source_system,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from commercetools.platform.models import Order as CTOrder

from commerce_coordinator.apps.commercetools.catalog_info.edx_utils import (
get_course_mode_from_ct_order,
get_edx_items,
get_edx_lms_user_id,
get_edx_lms_user_name,
Expand Down Expand Up @@ -58,6 +59,9 @@ def test_get_edx_items(self):
def test_is_edx_lms_order(self):
self.assertTrue(is_edx_lms_order(self.order))

def test_get_course_mode_from_ct_order(self):
self.assertEqual(get_course_mode_from_ct_order(self.order), 'certified')

def test_get_edx_lms_user_id(self):
self.assertEqual(get_edx_lms_user_id(self.user), DEFAULT_EDX_LMS_USER_ID)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"name": "brand-text",
"value": "MichiganX"
},
{
"name": "mode",
"value": "certified"
},
{
"name": "date-created",
"value": "2019-08-21T00:02:00.000Z"
Expand Down

0 comments on commit 0c2dddc

Please sign in to comment.