feat: B2C Subscription Inclusion Flag for Program Algolia Reindex#63
feat: B2C Subscription Inclusion Flag for Program Algolia Reindex#63skumargupta83 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Algolia proxy model layer to expose the b2c_subscription_inclusion flag for indexing (with accompanying test coverage), aligning course/program Algolia representations with the underlying product models.
Changes:
- Added a
b2c_subscription_inclusionaccessor onAlgoliaBasicModelFieldsMixinand removed the prior custom getter/setter override onAlgoliaProxyCourse. - Added new tests intended to validate
b2c_subscription_inclusionbehavior for course and program Algolia proxy models.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
course_discovery/apps/course_metadata/algolia_models.py |
Adjusts how b2c_subscription_inclusion is surfaced on Algolia proxy models/mixins. |
course_discovery/apps/course_metadata/tests/test_algolia_models.py |
Adds tests covering b2c_subscription_inclusion for course/program Algolia proxy objects. |
Comments suppressed due to low confidence (2)
course_discovery/apps/course_metadata/tests/test_algolia_models.py:982
- Same issue as the previous test:
AlgoliaProxyCourse(product=course)is not a supported constructor and will raiseTypeError. Build anAlgoliaProxyCourseinstance viaAlgoliaProxyCourseFactoryand assert on its persisted field value instead.
course = CourseFactory(b2c_subscription_inclusion=False)
proxy_course = AlgoliaProxyCourse(product=course)
self.assertFalse(proxy_course.b2c_subscription_inclusion)
course_discovery/apps/course_metadata/tests/test_algolia_models.py:994
- Same issue as the previous program test:
AlgoliaProxyProgram(product=program)is not a supported constructor. Create the proxy program viaAlgoliaProxyProgramFactoryand assert against the model field value.
program = ProgramFactory(b2c_subscription_inclusion=False)
proxy_program = AlgoliaProxyProgram(product=program)
self.assertFalse(proxy_program.b2c_subscription_inclusion)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @property | ||
| def b2c_subscription_inclusion(self): | ||
| """Return the b2c_subscription_inclusion value from the underlying product instance.""" | ||
| # If this is a wrapped product (using the product attribute), get from product | ||
| if hasattr(self, 'product') and self.product is not None: | ||
| return getattr(self.product, 'b2c_subscription_inclusion', False) | ||
| # Otherwise get from the instance itself, avoiding infinite recursion by checking __dict__ | ||
| return self.__dict__.get('b2c_subscription_inclusion', False) |
| course = CourseFactory(b2c_subscription_inclusion=True) | ||
| proxy_course = AlgoliaProxyCourse(product=course) | ||
| self.assertTrue(proxy_course.b2c_subscription_inclusion) |
| program = ProgramFactory(b2c_subscription_inclusion=True) | ||
| proxy_program = AlgoliaProxyProgram(product=program) | ||
| self.assertTrue(proxy_program.b2c_subscription_inclusion) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
course_discovery/apps/course_metadata/algolia_models.py:236
- AlgoliaBasicModelFieldsMixin.b2c_subscription_inclusion is unlikely to be used by AlgoliaProxyCourse/AlgoliaProxyProgram because both Course and Program define a concrete
b2c_subscription_inclusionmodel field (so attribute resolution will hit the field descriptor on the base model before this mixin). This makes the added property effectively dead code and can be misleading; it also risks shadowing the field if the inheritance order ever changes.
Consider removing this mixin property (or moving any special handling to the actual wrapper class that uses self.product).
# If this is a wrapped product (using the product attribute), get from product
if hasattr(self, 'product') and self.product is not None:
return getattr(self.product, 'b2c_subscription_inclusion', False)
# Otherwise get from the instance itself, avoiding infinite recursion by checking __dict__
return self.__dict__.get('b2c_subscription_inclusion', False)
| def test_b2c_subscription_inclusion_true_for_program(self): | ||
| """Verify b2c_subscription_inclusion is True for a program when set.""" | ||
| program = ProgramFactory(b2c_subscription_inclusion=True) | ||
| proxy_program = AlgoliaProxyProgram.objects.get(pk=program.pk) | ||
| self.assertTrue(proxy_program.b2c_subscription_inclusion) |
No description provided.