Skip to content

Commit

Permalink
chore: add override testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 authored and hamza-56 committed Sep 12, 2024
1 parent de88767 commit 8b5f4b7
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
"""
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(degree.uuid.hex)
]
self.assertEqual(len(matching_rows), 1)

row = matching_rows[0]
self.assertEqual(row["UUID"], str(degree.uuid.hex))
self.assertEqual(row["Title"], degree.title)
self.assertIn(degree.primary_subject_override.name, row["Subjects"])
self.assertEqual(row["Languages"], degree.language_override.code)

@mock.patch(
"course_discovery.apps.course_metadata.management.commands.populate_product_catalog.Command.get_products"
)
Expand Down

0 comments on commit 8b5f4b7

Please sign in to comment.