Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/utils/test_autotailor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 6 additions & 2 deletions utils/autotailor
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Loading