Skip to content

Commit

Permalink
feat: use org short code override for bootcamps in url slug creation …
Browse files Browse the repository at this point in the history
…logic
  • Loading branch information
AliAdnanSohail committed Sep 20, 2023
1 parent 8a19585 commit a43d253
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def setUp(self):
)
self.exec_ed_course1.authoring_organizations.add(self.organization)
self.bootcamp_course_1 = CourseFactory(
draft=True, product_source=self.external_product_source, partner=partner, type=bootcamp_type
draft=True, product_source=self.external_product_source, partner=partner, type=bootcamp_type,
organization_short_code_override=''
)
self.bootcamp_course_1.authoring_organizations.add(self.organization)
self.bootcamp_course_1.subjects.add(self.subject)
Expand Down
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_automate_url_restructuring_for_bootcamps_with_feature_flag_state(
Tests automate url slug restructuring for bootcamps must work under its relevant feature flag
"""
bootcamp_type = CourseTypeFactory(slug=CourseType.BOOTCAMP_2U)
bootcamp_course_draft = CourseFactory(draft=True, type=bootcamp_type)
bootcamp_course_draft = CourseFactory(draft=True, type=bootcamp_type, organization_short_code_override='')
draft_course_run = CourseRunFactory(draft=True, course=bootcamp_course_draft)
subject = SubjectFactory(name='Subject1')
org = OrganizationFactory(name='organization1')
Expand Down
28 changes: 26 additions & 2 deletions course_discovery/apps/course_metadata/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ def test_get_slug_for_bootcamp_course(self):
It will verify that slug are generated correctly for bootcamp courses
"""
bootcamp_type = CourseTypeFactory(slug=CourseType.BOOTCAMP_2U)
course = CourseFactory(title='test-bootcamp', type=bootcamp_type)
course = CourseFactory(title='test-bootcamp', type=bootcamp_type, organization_short_code_override='')
org = OrganizationFactory(name='test-organization')
course.authoring_organizations.add(org)

Expand All @@ -1117,6 +1117,28 @@ def test_get_slug_for_bootcamp_course(self):
assert error is None
assert slug == f"boot-camps/{subject.slug}/{org.name}-{slugify(course.title)}"

def test_get_slug_for_bootcamp_course__organization_short_code_override(self):
"""
It will verify that during slug creation it will give priority to organization_short_code_override if it exists
otherwise it will use organization name
"""
bootcamp_type = CourseTypeFactory(slug=CourseType.BOOTCAMP_2U)
course = CourseFactory(title='test-bootcamp', type=bootcamp_type, organization_short_code_override='')
org = OrganizationFactory(name='test-organization')
course.authoring_organizations.add(org)
subject = SubjectFactory(name='business')
course.subjects.add(subject)
slug, error = utils.get_slug_for_course(course)

assert error is None
assert slug == f"boot-camps/{subject.slug}/{org.name}-{slugify(course.title)}"
org_short_code_override = 'org_override'
course.organization_short_code_override = org_short_code_override
course.save()
slug, error = utils.get_slug_for_course(course)
assert error is None
assert slug == f"boot-camps/{subject.slug}/{org_short_code_override}-{slugify(course.title)}"

def test_get_slug_for_course__with_no_url_slug(self):
course = CourseFactory(title='test-title')
subject = SubjectFactory(name='business')
Expand Down Expand Up @@ -1216,7 +1238,9 @@ def test_get_slug_for_bootcamp_course__with_existing_url_slug(self):

# Create and test multiple courses with the same title, subject, and organization
for i in range(1, 3):
course = CourseFactory(title='test-title', type=bootcamp_type, partner=partner)
course = CourseFactory(
title='test-title', type=bootcamp_type, partner=partner, organization_short_code_override=''
)
course.authoring_organizations.add(org)
course.subjects.add(subject)
course.save()
Expand Down
5 changes: 3 additions & 2 deletions course_discovery/apps/course_metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,14 +1072,15 @@ def create_slug_for_bootcamps():
logger.info(error)
return None, error
primary_subject_slug = course_subjects[0].slug
organization_short_code = course.organization_short_code_override or organization_slug

slug = f'boot-camps/{primary_subject_slug}/{organization_slug}-{course_slug}'
slug = f'boot-camps/{primary_subject_slug}/{organization_short_code}-{course_slug}'
if is_existing_slug(slug, course):
logger.info(
f"Bootcamp Slug '{slug}' already exists in DB, recreating slug by adding a number in course_title"
)
course_slug = f"{slugify(course.title)}-{get_existing_slug_count(slug) + 1}"
slug = f"boot-camps/{primary_subject_slug}/{organization_slug}-{course_slug}"
slug = f"boot-camps/{primary_subject_slug}/{organization_short_code}-{course_slug}"
return slug, None

def create_slug_for_ocm():
Expand Down

0 comments on commit a43d253

Please sign in to comment.