Skip to content

Commit

Permalink
feat: add variant_id to seat info for ExecEd courses
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jan 4, 2024
1 parent d2a66ba commit 215511e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
8 changes: 7 additions & 1 deletion ecommerce/core/tests/test_create_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ def test_handle_with_existing_course(self):
partner=self.partner
)

seat_attrs = {'certificate_type': '', 'expires': None, 'price': 0.00, 'id_verification_required': False}
seat_attrs = {
'certificate_type': '',
'expires': None,
'price': 0.00,
'id_verification_required': False,
'variant_id': '00000000-0000-0000-0000-000000000000'
}
course.create_or_update_seat(**seat_attrs)

with mock.patch.object(Course, 'publish_to_lms', return_value=None) as mock_publish:
Expand Down
6 changes: 5 additions & 1 deletion ecommerce/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def create_or_update_seat(
remove_stale_modes=True,
create_enrollment_code=False,
sku=None,
variant_id=None,
):
"""
Creates and updates course seat products.
Expand All @@ -174,7 +175,8 @@ def create_or_update_seat(
create_enrollment_code(bool): Whether an enrollment code is created in addition to the seat.
sku(str): The partner_sku for the product stored as part of the Stock Record. This is used
to perform a GET on the seat as a unique identifier both Ecommerce and Discovery know about.
variant_id(uuid): The variant_id for the product stored as part of the Stock Record.
It is used specifically in case of Executive Education courses to create enrollment on getsmarter.
Returns:
Product: The seat that has been created or updated.
"""
Expand Down Expand Up @@ -218,6 +220,8 @@ def create_or_update_seat(
seat.attr.certificate_type = certificate_type
seat.attr.course_key = course_id
seat.attr.id_verification_required = id_verification_required
if variant_id:
seat.attr.variant_id = variant_id
if certificate_type in ENROLLMENT_CODE_SEAT_TYPES and create_enrollment_code:
self._create_or_update_enrollment_code(
certificate_type, id_verification_required, self.partner, price, expires
Expand Down
16 changes: 12 additions & 4 deletions ecommerce/courses/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_save_creates_parent_seat(self):
self.assertEqual(parent.attr.course_key, course.id)

def assert_course_seat_valid(self, seat, course, certificate_type, id_verification_required, price,
credit_provider=None, credit_hours=None):
credit_provider=None, credit_hours=None, variant_id=None):
""" Ensure the given seat has the correct attribute values. """
self.assertEqual(seat.structure, Product.CHILD)
# pylint: disable=protected-access
Expand All @@ -108,6 +108,9 @@ def assert_course_seat_valid(self, seat, course, certificate_type, id_verificati
self.assertEqual(seat.attr.id_verification_required, id_verification_required)
self.assertEqual(seat.stockrecords.first().price_excl_tax, price)

if variant_id:
self.assertEqual(seat.attr.variant_id, variant_id)

if credit_provider:
self.assertEqual(seat.attr.credit_provider, credit_provider)

Expand All @@ -132,7 +135,8 @@ def test_create_or_update_seat(self):
# Test seat update
price = 10
course.create_or_update_seat(
certificate_type, id_verification_required, price, sku=seat.stockrecords.first().partner_sku
certificate_type, id_verification_required, price, sku=seat.stockrecords.first().partner_sku,
variant_id='00000000-0000-0000-0000-000000000000'
)

# Again, only two seats with one being the parent seat product.
Expand Down Expand Up @@ -202,12 +206,14 @@ def test_update_credit_seat(self):
certificate_type = 'credit'
id_verification_required = True
price = 10
variant_id = '00000000-0000-0000-0000-000000000000'
credit_seat = course.create_or_update_seat(
certificate_type,
id_verification_required,
price,
credit_provider=credit_provider,
credit_hours=credit_hours
credit_hours=credit_hours,
variant_id=variant_id
)
credit_hours = 4
price = 100
Expand All @@ -218,6 +224,7 @@ def test_update_credit_seat(self):
credit_provider=credit_provider,
credit_hours=credit_hours,
sku=credit_seat.stockrecords.first().partner_sku,
variant_id=variant_id
)
self.assert_course_seat_valid(
credit_seat,
Expand All @@ -226,7 +233,8 @@ def test_update_credit_seat(self):
id_verification_required,
price,
credit_provider=credit_provider,
credit_hours=credit_hours
credit_hours=credit_hours,
variant_id=variant_id
)

def test_collision_avoidance(self):
Expand Down
2 changes: 2 additions & 0 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ def save(course, product, create_enrollment_code):
stockrecords = product.get('stockrecords', [])
if stockrecords:
sku = stockrecords[0].get('partner_sku')
variant_id = attrs.get('variant_id')

seat = course.create_or_update_seat(
certificate_type,
Expand All @@ -781,6 +782,7 @@ def save(course, product, create_enrollment_code):
credit_hours=credit_hours,
create_enrollment_code=create_enrollment_code,
sku=sku,
variant_id=variant_id
)

# As a convenience to our caller, provide the SKU in the returned product serialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 3.2.20 on 2024-01-04 09:32

from django.db import migrations

Check warning on line 3 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L3

Added line #L3 was not covered by tests

from ecommerce.core.constants import SEAT_PRODUCT_CLASS_NAME

Check warning on line 5 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L5

Added line #L5 was not covered by tests


def create_product_attribute(apps, schema_editor):

Check warning on line 8 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L8

Added line #L8 was not covered by tests
""" Create a product attribute for course seat product class"""
ProductAttribute = apps.get_model("catalogue", "ProductAttribute")
ProductClass = apps.get_model("catalogue", "ProductClass")

Check warning on line 11 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L10-L11

Added lines #L10 - L11 were not covered by tests

for class_iter in (ProductAttribute, ProductClass):
class_iter.skip_history_when_saving = True

Check warning on line 14 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L13-L14

Added lines #L13 - L14 were not covered by tests

seat = ProductClass.objects.get(name=SEAT_PRODUCT_CLASS_NAME)

Check warning on line 16 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L16

Added line #L16 was not covered by tests

# Create product attribute for course seat products
product_attr = ProductAttribute(

Check warning on line 19 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L19

Added line #L19 was not covered by tests
product_class=seat,
name="variant_id",
code="variant_id",
type="text",
required=False
)
product_attr.save()

Check warning on line 26 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L26

Added line #L26 was not covered by tests

def remove_product_attribute(apps, schema_editor):

Check warning on line 28 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L28

Added line #L28 was not covered by tests
""" Reverse function. """
ProductAttribute = apps.get_model("catalogue", "ProductAttribute")
ProductAttribute.skip_history_when_saving = True
ProductAttribute.objects.filter(name='variant_id', product_class__name=SEAT_PRODUCT_CLASS_NAME).delete()

Check warning on line 32 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L30-L32

Added lines #L30 - L32 were not covered by tests

class Migration(migrations.Migration):

Check warning on line 34 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L34

Added line #L34 was not covered by tests

dependencies = [

Check warning on line 36 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L36

Added line #L36 was not covered by tests
('catalogue', '0055_sf_opp_line_item_ent_attr'),
]

operations = [

Check warning on line 40 in ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/catalogue/migrations/0056_add_variant_id_seat_product_attr.py#L40

Added line #L40 was not covered by tests
migrations.RunPython(create_product_attribute, remove_product_attribute),
]

0 comments on commit 215511e

Please sign in to comment.