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

fix: Course to have multiple seats with certificate_type attribute #3950

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ecommerce/courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ def toggle_enrollment_code_status(self, is_active):
enrollment_code = self.get_enrollment_code()
if enrollment_code:
if is_active:
seat = self.seat_products.get(
seat = self.seat_products.filter(
attributes__name='certificate_type',
attribute_values__value_text=enrollment_code.attr.seat_type
)
).order_by('-expires').first()
enrollment_code.expires = seat.expires if seat.expires else now() + timedelta(days=365)
else:
enrollment_code.expires = now() - timedelta(days=365)
Expand Down
21 changes: 19 additions & 2 deletions ecommerce/courses/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def test_seat_products(self):

# Create the seat products
seats = [course.create_or_update_seat('honor', False, 0),
course.create_or_update_seat('verified', True, 50, create_enrollment_code=True)]
self.assertEqual(course.products.count(), 4)
course.create_or_update_seat('verified', True, 50, create_enrollment_code=True),
course.create_or_update_seat('verified', True, 60),
course.create_or_update_seat('verified', True, 70)]
self.assertEqual(course.products.count(), 6)

# The property should return only the child seats.
self.assertEqual(set(course.seat_products), set(seats))
Expand Down Expand Up @@ -371,3 +373,18 @@ def test_deactivate_enrollment_code(self):
ec_expires = now() - timedelta(days=365)
self.assertEqual(course.get_enrollment_code().expires, ec_expires)
self.assertIsNone(course.enrollment_code_product)

def test_toggle_enrollment_code_with_multiple_seats(self):
"""Verify enrollment code expiration date is set when course has multiple seats"""
seat_one_expires = now() + timedelta(days=365)
seat_two_expires = now() + timedelta(days=366)
seat_three_expires = now() + timedelta(days=367)
course, _, enrollment_code = self.create_course_seat_and_enrollment_code(expires=seat_one_expires)
course.create_or_update_seat("honor", False, 0)
course.create_or_update_seat("verified", True, 10, expires=seat_two_expires)
course.create_or_update_seat("verified", True, 10, expires=seat_three_expires)
course.toggle_enrollment_code_status(True)
ec_expires = seat_three_expires

self.assertEqual(course.get_enrollment_code().expires, ec_expires)
self.assertEqual(course.enrollment_code_product, enrollment_code)
3 changes: 2 additions & 1 deletion ecommerce/extensions/catalogue/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def test_generate_sku_for_course_seat(self, course_id):
certificate_type = 'audit'
product = course.create_or_update_seat(certificate_type, False, 0)

_hash = '{} {} {} {} {}'.format(certificate_type, course_id, 'False', '', self.partner.id).encode('utf-8')
_hash = '{} {} {} {} {} {}'.format(certificate_type, course_id, 'False', '', product.id,
self.partner.id).encode('utf-8')
_hash = md5(_hash.lower()).hexdigest()[-7:]
# verify that generated sku has partner 'short_code' as prefix
expected = _hash.upper()
Expand Down
1 change: 1 addition & 0 deletions ecommerce/extensions/catalogue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def generate_sku(product, partner):
str(product.attr.course_key),
str(product.attr.id_verification_required),
getattr(product.attr, 'credit_provider', ''),
str(product.id),
str(partner.id)
)).encode('utf-8')
elif product.is_course_entitlement_product:
Expand Down