From 053981f77fccdab6fc1c20e701f79a5affb8ba18 Mon Sep 17 00:00:00 2001 From: Matthew Burket Date: Thu, 2 Apr 2026 07:33:21 -0500 Subject: [PATCH] Backport Allow for only id or base_profile_id in JSON Add tests for the changes Backport #2318 --- tests/utils/test_autotailor.py | 11 +++++++++++ utils/autotailor | 8 ++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/utils/test_autotailor.py b/tests/utils/test_autotailor.py index 2b9a8ce15f..2f8a4af06e 100644 --- a/tests/utils/test_autotailor.py +++ b/tests/utils/test_autotailor.py @@ -120,3 +120,14 @@ def test_get_datastream_uri(): uri = t._get_datastream_uri() assert uri.startswith("file://") assert "relative/path/to/ds.xml" in uri + +def test_no_id(): + p = autotailor.Profile() + profile_dict = None + file_path = pathlib.Path(__file__).parent.joinpath("custom_no_ids.json") + with open(file_path) as fp: + json_data = json.load(fp) + profile_dict = json_data["profiles"][0] + with pytest.raises(ValueError) as e: + p.import_json_tailoring_profile(profile_dict) + assert str(e.value) == "You must define a base_profile_id or an id" diff --git a/utils/autotailor b/utils/autotailor index 43a2c1b3e9..ae977b36ea 100755 --- a/utils/autotailor +++ b/utils/autotailor @@ -245,7 +245,8 @@ class Tailoring: root.set("id", self.id) benchmark = ET.SubElement(root, "{%s}benchmark" % NS) - datastream_uri = self._get_datastream_uri() + datastream_uri = pathlib.Path( + self.original_ds_filename).absolute().as_uri() benchmark.set("href", datastream_uri) version = ET.SubElement(root, "{%s}version" % NS) @@ -255,6 +256,8 @@ class Tailoring: profile = ET.SubElement(root, "{%s}Profile" % NS) profile.set("id", self._full_profile_id(self.profile_id)) profile.set("extends", self._full_profile_id(self.extends)) + if self.extends: + profile.set("extends", self._full_profile_id(self.extends)) # Title has to be there due to the schema definition. title = ET.SubElement(profile, "{%s}title" % NS) @@ -336,7 +339,8 @@ class Tailoring: raise ValueError("JSON Tailoring does not define any profiles.") self.extends = tailoring["base_profile_id"] - + if not tailoring.get("base_profile_id") and not tailoring.get("id"): + raise ValueError("You must define a base_profile_id or an id") self.profile_id = tailoring.get("id", self.profile_id) self.profile_title = tailoring.get("title", self.profile_title)