From 18d78aaa7d8774f99439f0917bf173e6bbd627dc Mon Sep 17 00:00:00 2001 From: Muhammad Afaq Shuaib Date: Thu, 19 Sep 2024 20:52:06 +0500 Subject: [PATCH] chore: added support for default language for degree export (#4447) --- .../commands/populate_product_catalog.py | 2 +- .../tests/test_populate_product_catalog.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py index 340b9d5527..3ceeef149d 100644 --- a/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py +++ b/course_discovery/apps/course_metadata/management/commands/populate_product_catalog.py @@ -170,7 +170,7 @@ def get_transformed_data(self, product, product_type): translation.name for subject in product.active_subjects for translation in subject.spanish_translations ), - "Languages": ", ".join(language.code for language in product.active_languages), + "Languages": ", ".join(language.code for language in product.active_languages) or 'en-us', "Marketing Image": product.card_image.url if product.card_image else "", }) 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 88e359f885..b2eec9cf54 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 @@ -235,6 +235,18 @@ def test_populate_product_catalog_excludes_non_marketable_degrees(self): authoring_organizations=[self.organization], card_image=factory.django.ImageField() ) + marketable_degree_with_no_language = 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 - with empty language field", + authoring_organizations=[self.organization], + card_image=factory.django.ImageField(), + language_override=None, + ) marketable_degree_2 = DegreeFactory.create( product_source=self.source, @@ -283,6 +295,15 @@ 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") + # Check that the marketable degree with no language field is in the CSV + matching_rows = [ + row for row in rows if row["UUID"] == str(marketable_degree_with_no_language.uuid.hex) + ] + self.assertEqual(len(matching_rows), 1, + f"Marketable degree '{marketable_degree_with_no_language.title}' should be in the CSV") + # Check that the marketable degree with no language field has the default language populated + self.assertEqual(matching_rows[0].get("Languages"), 'en-us') + 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.