Skip to content

Commit 7ca997d

Browse files
authored
Add published URL to metadata for build (#2676)
* Add published URL to metadata for build * Handle None values without casting to string * Update test for None value handling * Use helper function instead of accessing field directly * Use helper function instead of accessing field directly in test
1 parent bd42bb4 commit 7ca997d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

content_sync/serializers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def serialize(self, website_content: WebsiteContent) -> str:
143143
metadata = website_content.metadata
144144
if website_content.type == CONTENT_TYPE_METADATA:
145145
metadata["site_uid"] = str(website_content.website.uuid)
146-
metadata["site_short_id"] = str(website_content.website.short_id)
146+
metadata["site_short_id"] = website_content.website.short_id
147+
metadata["site_url_path"] = website_content.website.get_url_path()
147148

148149
return json.dumps(
149150
self.serialize_contents(metadata, website_content.title),

content_sync/serializers_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def test_hugo_file_serialize(settings, markdown, exp_sections):
146146
+ [f"{k}: {v}" for k, v in metadata.items()]
147147
)
148148
assert (
149-
f"image: /media/{content.website.url_path}/{content.file.name.split('/')[-1]}"
149+
f"image: /media/{content.website.get_url_path()}/{content.file.name.split('/')[-1]}"
150150
in front_matter_lines
151151
)
152152
if exp_sections > 1:
@@ -319,8 +319,13 @@ def test_data_file_serialize(serializer_cls):
319319
@pytest.mark.django_db
320320
def test_metadata_file_serialize():
321321
"""JsonFileSerializer should create the expected data file contents for sitemetadata files"""
322+
website = WebsiteFactory.create(
323+
short_id="somecourse-f25",
324+
url_path="courses/somecourse-fall-2025",
325+
)
322326
metadata = {"metadata1": "dummy value 1", "metadata2": "dummy value 2"}
323327
content = WebsiteContentFactory.create(
328+
website=website,
324329
text_id="abcdefg",
325330
title="Content Title",
326331
type="sitemetadata",
@@ -334,6 +339,8 @@ def test_metadata_file_serialize():
334339
**metadata,
335340
"site_uid": str(content.website.uuid),
336341
"title": "Content Title",
342+
"site_short_id": content.website.short_id,
343+
"site_url_path": content.website.get_url_path(),
337344
}
338345

339346

0 commit comments

Comments
 (0)