Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila committed May 13, 2024
1 parent f18f0f9 commit f65796f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 21 deletions.
7 changes: 1 addition & 6 deletions course_discovery/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,13 +1638,8 @@ class CourseWithRecommendationsSerializer(FlexFieldsSerializerMixin, TimestampMo
recommendations = serializers.SerializerMethodField()

def get_recommendations(self, course):
recommended_courses = course.recommendations()
forbidden_runs = get_forbidden_runs(self.context['request'])
runs = CourseRun.objects.exclude(restricted_run__restriction_type__in=forbidden_runs)
prefetch_related_objects(recommended_courses, Prefetch(
'course_runs',
queryset=runs.select_related('type').prefetch_related('seats')),
)
recommended_courses = course.recommendations(forbidden_runs=forbidden_runs)
return CourseRecommendationSerializer(
recommended_courses,
many=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@pytest.mark.usefixtures('course_run_states')
class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixin, APITestCase):
""" Tests for the catalog resource. """
max_diff=None
catalog_list_url = reverse('api:v1:catalog-list')

def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion course_discovery/apps/api/v1/views/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def courses(self, request, id=None): # pylint: disable=redefined-builtin, unuse
queryset = queryset.available()
course_runs = course_runs.active().enrollable().marketable()
forbidden_runs = get_forbidden_runs(request)
course_runs = CourseRun.objects.exclude(restricted_run__restriction_type__in=forbidden_runs)
course_runs = course_runs.exclude(restricted_run__restriction_type__in=forbidden_runs)
queryset = serializers.CatalogCourseSerializer.prefetch_queryset(
self.request.site.partner,
queryset=queryset,
Expand Down
4 changes: 3 additions & 1 deletion course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ def advertised_course_run(self):
def has_marketable_run(self):
return any(run.is_marketable for run in self.course_runs.all())

def recommendations(self):
def recommendations(self, forbidden_runs=[]):
"""
Recommended set of courses for upsell after finishing a course. Returns de-duped list of Courses that:
A) belong in the same program as given Course
Expand All @@ -1922,6 +1922,7 @@ def recommendations(self):
)
.select_related('partner', 'type')
.prefetch_related(
Prefetch('course_runs', queryset=CourseRun.objects.exclude(restricted_run__restriction_type__in=forbidden_runs).select_related('type').prefetch_related('seats')),
'authoring_organizations',
'_official_version'
)
Expand All @@ -1936,6 +1937,7 @@ def recommendations(self):
)
.select_related('partner', 'type')
.prefetch_related(
Prefetch('course_runs', queryset=CourseRun.objects.exclude(restricted_run__restriction_type__in=forbidden_runs).select_related('type').prefetch_related('seats')),
'authoring_organizations',
'_official_version'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def get_model_object_by_instances(self, instances):
Provide Model objects by elasticsearch response instances.
Fetches all the incoming instances at once and returns model queryset.
"""
# import pdb
# pdb.set_trace()

restriction_list=self.context['request'].query_params.get('restriction_list', '').split(',')
forbidden = list(set(CourseRunRestrictionType.values) - set(restriction_list))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,6 @@ class CourseSearchModelSerializer(DocumentDSLSerializerMixin, ContentTypeSeriali
"""
Serializer for course model elasticsearch document.
"""


def model_prefetch_queryset(self, queryset):
q = queryset.prefetch_related(
models.Prefetch(
'course_runs',
queryset=CourseRun.everything.filter(restricted_run__isnull=True)
)
)
return q

class Meta(CourseWithProgramsSerializer.Meta):
document = CourseDocument
fields = ContentTypeSerializer.Meta.fields + CourseWithProgramsSerializer.Meta.fields

0 comments on commit f65796f

Please sign in to comment.