Skip to content

Commit

Permalink
add algolia and learnerpathway tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zawan-ila committed May 14, 2024
1 parent 9dfdb55 commit 5409d97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
30 changes: 27 additions & 3 deletions course_discovery/apps/course_metadata/tests/test_algolia_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from conftest import TEST_DOMAIN
from course_discovery.apps.core.models import Currency, Partner
from course_discovery.apps.core.tests.factories import PartnerFactory, SiteFactory
from course_discovery.apps.course_metadata.algolia_models import AlgoliaProxyCourse, AlgoliaProxyProgram
from course_discovery.apps.course_metadata.algolia_models import AlgoliaProxyCourse, AlgoliaProxyProgram, AlgoliaProxyProduct
from course_discovery.apps.course_metadata.index import EnglishProductIndex

from course_discovery.apps.course_metadata.choices import ExternalProductStatus, ProgramStatus
from course_discovery.apps.course_metadata.models import CourseRunStatus, CourseType, ProductValue, ProgramType
from course_discovery.apps.course_metadata.tests.factories import (
AdditionalMetadataFactory, CourseFactory, CourseRunFactory, CourseTypeFactory, DegreeAdditionalMetadataFactory,
DegreeFactory, GeoLocationFactory, LevelTypeFactory, OrganizationFactory, ProductMetaFactory, ProgramFactory,
ProgramSubscriptionFactory, ProgramSubscriptionPriceFactory, ProgramTypeFactory, SeatFactory, SeatTypeFactory,
ProgramSubscriptionFactory, ProgramSubscriptionPriceFactory, ProgramTypeFactory, RestrictedCourseRunFactory, SeatFactory, SeatTypeFactory,
SourceFactory, SubjectFactory, VideoFactory
)
from course_discovery.apps.ietf_language_tags.models import LanguageTag
Expand Down Expand Up @@ -199,7 +201,7 @@ def setUpClass(cls):
Partner.objects.all().delete()
Site.objects.all().delete()
cls.site = SiteFactory(id=settings.SITE_ID, domain=TEST_DOMAIN)
cls.edxPartner = PartnerFactory(site=cls.site)
cls.edxPartner = PartnerFactory(site=cls.site, name='edX')
cls.edxPartner.name = 'edX'


Expand All @@ -212,6 +214,17 @@ def test_should_index(self):
course.authoring_organizations.add(OrganizationFactory())
assert course.should_index

def test_restricted_run_should_not_index(self):
'''
Test that if a course has only one run and that run is restricted,
it will not be indexed
'''
course = self.create_course_with_basic_active_course_run()
course.authoring_organizations.add(OrganizationFactory())
RestrictedCourseRunFactory(course_run=course.course_runs.first(), restriction_type="custom-b2b-enterprise")
qs = AlgoliaProxyCourse.prefetch_queryset()
assert not qs.first().should_index

def test_do_not_index_if_no_owners(self):
course = self.create_course_with_basic_active_course_run()
assert not course.should_index
Expand Down Expand Up @@ -637,6 +650,17 @@ def test_program_not_available_if_no_published_runs(self):

assert program.availability_level == []

def test_program_availability_if_restricted_runs(self):
'''
Test that program availability calculation ignores restricted runs
'''
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner)
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner)
run = self.attach_published_course_run(course=course, run_type="current and ends within two weeks")
program.courses.add(course)
RestrictedCourseRunFactory(course_run=run, restriction_type='custom-b2b-enterprise')
assert AlgoliaProxyProgram.prefetch_queryset().first().availability_level == []

def test_only_programs_with_spanish_courses_promoted_in_spanish_index(self):
all_spanish_program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, language_override=None)
mixed_language_program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, language_override=None)
Expand Down
20 changes: 18 additions & 2 deletions course_discovery/apps/learner_pathway/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from course_discovery.apps import learner_pathway
from course_discovery.apps.core.tests.factories import UserFactory
from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory
from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory, RestrictedCourseRunFactory
from course_discovery.apps.learner_pathway.choices import PathwayStatus
from course_discovery.apps.learner_pathway.tests.factories import (
LearnerPathwayCourseFactory, LearnerPathwayFactory, LearnerPathwayProgramFactory, LearnerPathwayStepFactory
Expand Down Expand Up @@ -90,7 +90,7 @@ def setUp(self):
course__title=LEARNER_PATHWAY_DATA['steps'][0]['courses'][0]['title'],
course__short_description=LEARNER_PATHWAY_DATA['steps'][0]['courses'][0]['short_description'],
)
__ = CourseRunFactory(
self.learner_pathway_course__course_run = CourseRunFactory(
course=self.learner_pathway_course.course,
key=LEARNER_PATHWAY_DATA['steps'][0]['courses'][0]['course_runs'][0]['key'],
status='published',
Expand Down Expand Up @@ -170,6 +170,22 @@ def test_learner_pathway_api_filtering(self):
assert data['results'][0]['uuid'] == self.learner_pathway.uuid
assert data['results'][1]['uuid'] == another_learner_pathway.uuid

@ddt.data(True, False)
def test_learner_pathway_restricted_runs(self, add_restriction_param):
restricted_run = CourseRunFactory(
course=self.learner_pathway_course.course,
key='course-v1:AA+AA101+3T2024',
status='published',
)
RestrictedCourseRunFactory(course_run=restricted_run, restriction_type='custom-b2c')
url = f'/api/v1/learner-pathway/'
if add_restriction_param:
url += '?restriction_list=custom-b2c'

api_response = self.client.get(url)
data = api_response.json()
assert len(data['results'][0]['steps'][0]['courses'][0]['course_runs']) == 2 if add_restriction_param else 1

def test_learner_pathway_api_returns_active_pathway_only(self):
"""
Verify that learner pathway api returns active pathway only.
Expand Down

0 comments on commit 5409d97

Please sign in to comment.