Skip to content

Commit 053981f

Browse files
committed
Backport Allow for only id or base_profile_id in JSON
Add tests for the changes Backport #2318
1 parent a9f8018 commit 053981f

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

tests/utils/test_autotailor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,14 @@ def test_get_datastream_uri():
120120
uri = t._get_datastream_uri()
121121
assert uri.startswith("file://")
122122
assert "relative/path/to/ds.xml" in uri
123+
124+
def test_no_id():
125+
p = autotailor.Profile()
126+
profile_dict = None
127+
file_path = pathlib.Path(__file__).parent.joinpath("custom_no_ids.json")
128+
with open(file_path) as fp:
129+
json_data = json.load(fp)
130+
profile_dict = json_data["profiles"][0]
131+
with pytest.raises(ValueError) as e:
132+
p.import_json_tailoring_profile(profile_dict)
133+
assert str(e.value) == "You must define a base_profile_id or an id"

utils/autotailor

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ class Tailoring:
245245
root.set("id", self.id)
246246

247247
benchmark = ET.SubElement(root, "{%s}benchmark" % NS)
248-
datastream_uri = self._get_datastream_uri()
248+
datastream_uri = pathlib.Path(
249+
self.original_ds_filename).absolute().as_uri()
249250
benchmark.set("href", datastream_uri)
250251

251252
version = ET.SubElement(root, "{%s}version" % NS)
@@ -255,6 +256,8 @@ class Tailoring:
255256
profile = ET.SubElement(root, "{%s}Profile" % NS)
256257
profile.set("id", self._full_profile_id(self.profile_id))
257258
profile.set("extends", self._full_profile_id(self.extends))
259+
if self.extends:
260+
profile.set("extends", self._full_profile_id(self.extends))
258261

259262
# Title has to be there due to the schema definition.
260263
title = ET.SubElement(profile, "{%s}title" % NS)
@@ -336,7 +339,8 @@ class Tailoring:
336339
raise ValueError("JSON Tailoring does not define any profiles.")
337340

338341
self.extends = tailoring["base_profile_id"]
339-
342+
if not tailoring.get("base_profile_id") and not tailoring.get("id"):
343+
raise ValueError("You must define a base_profile_id or an id")
340344
self.profile_id = tailoring.get("id", self.profile_id)
341345
self.profile_title = tailoring.get("title", self.profile_title)
342346

0 commit comments

Comments
 (0)