Skip to content

Commit

Permalink
adjust department names (#1253)
Browse files Browse the repository at this point in the history
* department and school loading functions should update data based on id, not on the name property which could change

* update department and school data, remove unnecessary date fields

* update department constants

* regenerate openapi

* change department_upserted hook to match its update_or_create on search_filter instead of name because name can change, and search_filter should stay the same since it's based on department_id

* fix test data

* don't also match on name

* add a test for renaming departments and updating the channel
  • Loading branch information
gumaerc authored Jul 12, 2024
1 parent 4c3f76d commit dcd9c01
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 305 deletions.
4 changes: 2 additions & 2 deletions channels/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def department_upserted(self, department, overwrite):
channel = None
elif department.school and (overwrite or not channel):
channel, _ = Channel.objects.update_or_create(
name=slugify(department.name),
search_filter=f"department={department.department_id}",
channel_type=ChannelType.department.name,
defaults={
"name": slugify(department.name),
"title": department.name,
"search_filter": f"department={department.department_id}",
},
)
ChannelDepartmentDetail.objects.update_or_create(
Expand Down
21 changes: 21 additions & 0 deletions channels/plugins_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ def test_search_index_plugin_department_delete():
)


@pytest.mark.django_db()
@pytest.mark.parametrize("overwrite", [True, False])
def test_search_index_plugin_department_rename(overwrite):
"""The plugin function should update the channel title when the department name changes"""
channel = ChannelFactory.create(is_department=True)
department = channel.department_detail.department
old_title = channel.title
assert department is not None
new_name = "New Name"
department.name = new_name
department.save()
updated_channel, updated = ChannelPlugin().department_upserted(
department, overwrite
)
if updated:
assert updated_channel.title == new_name
else:
assert updated_channel.title == old_title
assert updated is overwrite


@pytest.mark.django_db()
@pytest.mark.parametrize("overwrite", [True, False])
def test_search_index_plugin_offeror_upserted(overwrite):
Expand Down
98 changes: 49 additions & 49 deletions frontends/api/src/generated/v1/api.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions learning_resources/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ class LearningResourceRelationTypes(TextChoices):
"11": "Urban Studies and Planning",
"12": "Earth, Atmospheric, and Planetary Sciences",
"14": "Economics",
"15": "Sloan School of Management",
"15": "Management",
"16": "Aeronautics and Astronautics",
"17": "Political Science",
"18": "Mathematics",
"20": "Biological Engineering",
"21A": "Anthropology",
"21G": "Global Studies and Languages",
"21G": "Global Languages",
"21H": "History",
"21L": "Literature",
"21M": "Music and Theater Arts",
Expand All @@ -181,8 +181,8 @@ class LearningResourceRelationTypes(TextChoices):
"EC": "Edgerton Center",
"ES": "Experimental Study Group",
"ESD": "Engineering Systems Division",
"HST": "Health Sciences and Technology",
"IDS": "Institute for Data, Systems, and Society",
"HST": "Medical Engineering and Science",
"IDS": "Data, Systems, and Society",
"MAS": "Media Arts and Sciences",
"PE": "Athletics, Physical Education and Recreation",
"RES": "Supplemental Resources",
Expand Down
2 changes: 1 addition & 1 deletion learning_resources/etl/openedx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def test_transform_course( # noqa: PLR0913
"value": "MITx+15.071x",
"department": {
"department_id": "15",
"name": "Sloan School of Management",
"name": "Management",
},
"listing_type": CourseNumberType.primary.value,
"primary": True,
Expand Down
Loading

0 comments on commit dcd9c01

Please sign in to comment.