Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix: reduce length of program name (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Mar 19, 2024
1 parent df44fa2 commit 0409ba2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ def sync_programs(self, program_types):
if discovery_authoring_org:
auth_org = existing_org_dictionary.get(discovery_authoring_org.get('uuid'))
if auth_org:
# key fromd disco is not guarenteed to be a valid slugfield
program_key = slugify(discovery_program.get('marketing_slug'))
# key from disco is not guaranteed to be a valid slugfield.
# The current key pattern in disco looks something like /masters/program/name-of-the-program,
# so we should only use the piece of the marketing slug that contains the name of the program.
program_key = slugify(
discovery_program.get('marketing_slug').split('/')[-1],
max_length=100,
)
programs_to_create.append(Program(
discovery_uuid=discovery_program.get('uuid'),
managing_organization=auth_org,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ddt
from django.core.management import call_command
from django.db.utils import IntegrityError
from django.test import TestCase

from registrar.apps.core.api_client import DiscoveryServiceClient
Expand Down Expand Up @@ -301,17 +302,47 @@ def test_sync_programs_create_with_different_slugs(self):

def test_sync_programs_create_with_non_slug_marketing_slug(self):
""" Discovery keys that are not valid slugs should be slugified """
long_slug = (
'masters/online-masters/masters-in-business/'
'university-of-open-edx-online-masters-in-'
'business-analytics-statistics-and-computer-science-and-data-science-and-data-anlytics'
)
discovery_program = self.discovery_program_dict(
self.org.discovery_uuid,
'77777777-2222-3333-4444-555555555555',
'marketing/path/non-slug',
long_slug,
)
programs_to_sync = [
discovery_program,
]
self.assert_programs(programs_to_sync, 26)
created_program = Program.objects.get(discovery_uuid=discovery_program['uuid'])
self.assertEqual(created_program.key, 'marketing-path-non-slug')
self.assertEqual(
created_program.key,
'university-of-open-edx-online-masters-in-business-analytics-statistics-and-computer-science-and-data'
)

def test_sync_programs_multiple_non_slug_marketing_slug(self):
"""
Discovery keys that are not valid slugs should be slugified, and job should fail if keys are not unique
"""
discovery_program = self.discovery_program_dict(
self.org.discovery_uuid,
'77777777-2222-3333-4444-555555555555',
'marketing/online-masters/this-is-the-program-name',
)
another_discovery_program = self.discovery_program_dict(
self.org.discovery_uuid,
'77777777-2222-3333-4444-666666666666',
'marketing/masters/this-is-the-program-name',
)
programs_to_sync = [
discovery_program,
another_discovery_program,
]

with self.assertRaises(IntegrityError):
self.assert_programs(programs_to_sync, 26)

def test_sync_programs_with_different_slugs(self):
updated_discovery_program = self.discovery_program_dict(
Expand Down

0 comments on commit 0409ba2

Please sign in to comment.