diff --git a/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py b/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py index 511034edc38..bc0236f784b 100644 --- a/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py +++ b/course_discovery/apps/course_metadata/management/commands/tests/test_populate_product_catalog.py @@ -14,8 +14,9 @@ from course_discovery.apps.course_metadata.models import Course, CourseType, ProgramType from course_discovery.apps.course_metadata.tests.factories import ( CourseFactory, CourseRunFactory, CourseTypeFactory, DegreeFactory, OrganizationFactory, PartnerFactory, - ProgramTypeFactory, SeatFactory, SourceFactory + ProgramTypeFactory, SeatFactory, SourceFactory, SubjectFactory ) +from course_discovery.apps.ietf_language_tags.models import LanguageTag class PopulateProductCatalogCommandTests(TestCase): @@ -218,6 +219,48 @@ def test_populate_product_catalog_excludes_non_marketable_degrees(self): self.assertEqual(len(matching_rows), 1, f"Marketable degree '{marketable_degree.title}' should be in the CSV") + def test_populate_product_catalog_with_degrees_having_overrides(self): + """ + Test that the populate_product_catalog command includes the overridden subjects and languages for degrees. + """ + marketable_degree = DegreeFactory.create( + product_source=self.source, + partner=self.partner, + additional_metadata=None, + type=self.program_type, + status=ProgramStatus.Active, + marketing_slug="valid-marketing-slug", + title="Marketable Degree", + authoring_organizations=[self.organization], + card_image=factory.django.ImageField(), + primary_subject_override=SubjectFactory(name='Subject1'), + language_override=LanguageTag.objects.get(code='es'), + ) + + with NamedTemporaryFile() as output_csv: + call_command( + "populate_product_catalog", + product_type="degree", + output_csv=output_csv.name, + product_source="edx", + gspread_client_flag=False, + ) + + with open(output_csv.name, "r") as output_csv_file: + csv_reader = csv.DictReader(output_csv_file) + rows = list(csv_reader) + + matching_rows = [ + row for row in rows if row["UUID"] == str(marketable_degree.uuid.hex) + ] + self.assertEqual(len(matching_rows), 1) + + row = matching_rows[0] + self.assertEqual(row["UUID"], str(marketable_degree.uuid.hex)) + self.assertEqual(row["Title"], marketable_degree.title) + self.assertIn(marketable_degree.primary_subject_override.name, row["Subjects"]) + self.assertEqual(row["Languages"], marketable_degree.language_override.code) + @mock.patch( "course_discovery.apps.course_metadata.management.commands.populate_product_catalog.Command.get_products" )