diff --git a/course_discovery/apps/course_metadata/management/commands/tests/test_migrate_course_slugs.py b/course_discovery/apps/course_metadata/management/commands/tests/test_migrate_course_slugs.py index db3471b74c6..5059325940d 100644 --- a/course_discovery/apps/course_metadata/management/commands/tests/test_migrate_course_slugs.py +++ b/course_discovery/apps/course_metadata/management/commands/tests/test_migrate_course_slugs.py @@ -60,10 +60,12 @@ def setUp(self): self.exec_ed_course1 = CourseFactory( draft=True, product_source=self.external_product_source, partner=partner, type=ee_type_2u ) + self.exec_ed_course1.authoring_organizations.add(self.organization) self.bootcamp_course_1 = CourseFactory( - draft=True, product_source=self.product_source, partner=partner, type=bootcamp_type + draft=True, product_source=self.external_product_source, partner=partner, type=bootcamp_type ) - self.exec_ed_course1.authoring_organizations.add(self.organization) + self.bootcamp_course_1.authoring_organizations.add(self.organization) + self.bootcamp_course_1.subjects.add(self.subject) def test_migrate_course_slug_success_flow(self): with LogCapture(LOGGER_PATH) as log_capture: @@ -286,6 +288,38 @@ def test_migrate_course_slug_success_flow__executive_education(self): assert self.exec_ed_course1.active_url_slug == f"executive-education/test-organization-{slugify(self.exec_ed_course1.title)}" # pylint: disable=line-too-long + def test_migrate_course_slug_success_flow__bootcamps(self): + """ + It will verify that command is generating and saving correct slugs for bootcamp courses + """ + + with LogCapture(LOGGER_PATH) as log_capture: + current_slug_course1 = self.bootcamp_course_1.active_url_slug + + with override_waffle_switch(IS_SUBDIRECTORY_SLUG_FORMAT_ENABLED, active=True): + call_command( + 'migrate_course_slugs', + '--course_uuids', self.bootcamp_course_1.uuid, + '--course_type', CourseType.BOOTCAMP_2U, + '--product_source', self.external_product_source.slug + ) + log_capture.check_present( + ( + LOGGER_PATH, + 'INFO', + f"Updating slug for course with uuid {self.bootcamp_course_1.uuid} and title " + f"{self.bootcamp_course_1.title}, current slug is '{current_slug_course1}'" + ), + ( + LOGGER_PATH, + 'INFO', + f"course_uuid,old_slug,new_slug,error\n" + f"{self.bootcamp_course_1.uuid},{current_slug_course1},{self.bootcamp_course_1.active_url_slug},None\n" + ) + ) + + assert self.bootcamp_course_1.active_url_slug == f"boot-camps/{self.subject.slug}/test-organization-{slugify(self.bootcamp_course_1.title)}" # pylint: disable=line-too-long + def test_migrate_course_slug_success_flow__edx_bootcamps(self): """ It will verify that command is generating and saving correct slugs for executive education courses diff --git a/course_discovery/apps/course_metadata/tests/test_utils.py b/course_discovery/apps/course_metadata/tests/test_utils.py index 3a6377977d3..3e316b08fb2 100644 --- a/course_discovery/apps/course_metadata/tests/test_utils.py +++ b/course_discovery/apps/course_metadata/tests/test_utils.py @@ -1081,6 +1081,28 @@ def test_get_slug_for_exec_ed_course(self): assert error is None assert slug == f"executive-education/{organization.name}-{slugify(course.title)}" + + 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) + slug, error = utils.get_slug_for_course(course) + assert slug is None + assert error == f"Course with uuid {course.uuid} and title {course.title} does not have any authoring " \ + f"organizations" + + org = OrganizationFactory(name='test-organization') + course.authoring_organizations.add(org) + + slug, error = utils.get_slug_for_course(course) + 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)}" def test_get_slug_for_course__with_no_url_slug(self): course = CourseFactory(title='test-title') @@ -1169,6 +1191,47 @@ def test_get_slug_for_exec_ed_course__with_existing_url_slug(self): slug, error = utils.get_slug_for_course(course3) assert error is None assert slug == f"executive-education/{organization.name}-{slugify(course2.title)}-3" + + def test_get_slug_for_bootcamp_course__with_existing_url_slug(self): + """ + Test for bootcamp course with existing subdirectory url slug + """ + bootcamp_type = CourseTypeFactory(slug=CourseType.BOOTCAMP_2U) + partner = PartnerFactory() + subject = SubjectFactory(name='business') + org = OrganizationFactory(name='test-organization') + + course_1 = CourseFactory(title='test-title', type=bootcamp_type, partner=partner) + course_1.authoring_organizations.add(org) + course_1.subjects.add(subject) + course_1.save() + CourseUrlSlug.objects.filter(course=course_1).delete() + slug, error = utils.get_slug_for_course(course_1) + assert error is None + assert slug == f"boot-camps/{subject.slug}/{org.name}-{slugify(course_1.title)}" + course_1.set_active_url_slug(slug) + + # duplicate a new course with same title, subject and organization + course_2 = CourseFactory(title='test-title', type=bootcamp_type, partner=partner) + course_2.authoring_organizations.add(org) + course_2.subjects.add(subject) + course_2.save() + CourseUrlSlug.objects.filter(course=course_2).delete() + slug, error = utils.get_slug_for_course(course_2) + assert error is None + assert slug == f"boot-camps/{subject.slug}/{org.name}-{slugify(course_2.title)}-2" + course_2.set_active_url_slug(slug) + + # duplicate a new course with same title, subject and organization + course_3 = CourseFactory(title='test-title', type=bootcamp_type, partner=partner) + course_3.authoring_organizations.add(org) + course_3.subjects.add(subject) + course_3.save() + CourseUrlSlug.objects.filter(course=course_3).delete() + slug, error = utils.get_slug_for_course(course_3) + assert error is None + assert slug == f"boot-camps/{subject.slug}/{org.name}-{slugify(course_3.title)}-3" + course_3.set_active_url_slug(slug) def test_get_existing_slug_count(self): course1 = CourseFactory(title='test-title')