Skip to content

Commit

Permalink
test: add unit test of the method along with fixing some n+1 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Sep 4, 2024
1 parent b0a043d commit a4a40e8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_products(self, product_type, product_source):
]

if (product_type := product_type.lower()) in ['executive_education', 'bootcamp', 'ocm_course']:
queryset = Course.objects.available()
queryset = Course.objects.available().select_related('partner', 'type')

if product_type == 'ocm_course':
queryset = queryset.filter(type__slug__in=ocm_course_catalog_types)
Expand Down
4 changes: 2 additions & 2 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,8 +1718,8 @@ def languages_codes(self, exclude_inactive_runs=False):
exclude_inactive_runs (bool): whether to exclude inactive runs
"""
if exclude_inactive_runs:
return ','.join(set(course_run.language.code for course_run in self.active_course_runs.filter(language__isnull=False, restricted_run__isnull=True)))
return ','.join(set(course_run.language.code for course_run in self.course_runs.filter(language__isnull=False, restricted_run__isnull=True)))
return ', '.join(set(course_run.language.code for course_run in self.active_course_runs.filter(language__isnull=False, restricted_run__isnull=True)))
return ', '.join(set(course_run.language.code for course_run in self.course_runs.filter(language__isnull=False, restricted_run__isnull=True)))

@property
def first_enrollable_paid_seat_price(self):
Expand Down
24 changes: 24 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,30 @@ def test_image_url(self):
course.image = None
assert course.image_url == course.card_image_url

def test_language_codes(self):
partner = factories.PartnerFactory.create()
source = factories.SourceFactory.create(slug="edx")
course = factories.CourseFactory(
product_source=source,
partner=partner,
additional_metadata=None,
)
LanguageTag.objects.create(code='en', name='English')
course_run = CourseRunFactory(
course=Course.objects.all()[0],
status=CourseRunStatus.Published,
language=LanguageTag.objects.get(code='en')
)
SeatFactory.create(course_run=course_run)
CourseRunFactory(
course=Course.objects.all()[0],
status=CourseRunStatus.Unpublished,
language=LanguageTag.objects.get(code='es'),
enrollment_end=datetime.datetime.now() - datetime.timedelta(days=5)
)
assert course.languages_codes() in ['en, es', 'es, en']
assert course.languages_codes(exclude_inactive_runs=True) == 'en'

def test_validate_history_created_only_on_change(self):
"""
Validate that course history object would be created if the object is changed otherwise not.
Expand Down

0 comments on commit a4a40e8

Please sign in to comment.