From 26ee9e91e76afbc88fc585eed9c71d925ca6eec3 Mon Sep 17 00:00:00 2001 From: simleo Date: Fri, 22 Dec 2023 12:57:52 +0100 Subject: [PATCH] add contentUrl when fetching remote files --- rocrate/model/file.py | 1 + test/test_write.py | 1 + 2 files changed, 2 insertions(+) diff --git a/rocrate/model/file.py b/rocrate/model/file.py index 9251aeb..a5d1c43 100644 --- a/rocrate/model/file.py +++ b/rocrate/model/file.py @@ -59,6 +59,7 @@ def write(self, base_path): if self.fetch_remote: out_file_path.parent.mkdir(parents=True, exist_ok=True) urllib.request.urlretrieve(response.url, out_file_path) + self._jsonld['contentUrl'] = str(self.source) elif self.source is None: # Allows to record a File entity whose @id does not exist, see #73 warnings.warn(f"No source for {self.id}") diff --git a/test/test_write.py b/test/test_write.py index 10f0ec3..6fb57b6 100644 --- a/test/test_write.py +++ b/test/test_write.py @@ -150,6 +150,7 @@ def test_remote_uri(tmpdir, helpers, fetch_remote, validate_url, to_zip): if fetch_remote: out_file = out_crate.dereference(file_.id) assert (out_path / relpath).is_file() + assert out_file["contentUrl"] == url else: out_file = out_crate.dereference(url) assert not (out_path / relpath).exists()