From 12d546aece6558f59119f5eacc39d84ecc829b95 Mon Sep 17 00:00:00 2001 From: Ken Lui <116421546+kenlhlui@users.noreply.github.com> Date: Wed, 18 Jun 2025 15:22:51 -0400 Subject: [PATCH 1/3] Sanitize version string by removing non-numeric characters --- easyDataverse/dataverse.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/easyDataverse/dataverse.py b/easyDataverse/dataverse.py index 8d81bf5..a844b6f 100644 --- a/easyDataverse/dataverse.py +++ b/easyDataverse/dataverse.py @@ -227,6 +227,10 @@ def _version_is_compliant(self) -> bool: ) major, minor, *_ = response.json()["data"]["version"].split(".") + + # Remove all the non-numeric parts from the version string to avoid having leading 'v' or other characters. + major = "".join(filter(str.isdigit, major)) + minor = "".join(filter(str.isdigit, minor)) if int(major) >= 6: return True From 9fdd7ecfe7d4d10290cc097e2135b74cd63b5e2b Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Wed, 18 Jun 2025 21:57:47 +0200 Subject: [PATCH 2/3] test versions are extracted correctly --- easyDataverse/dataverse.py | 27 +++++++++++++++++++++----- tests/unit/test_dataverse.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/easyDataverse/dataverse.py b/easyDataverse/dataverse.py index a844b6f..8775f0a 100644 --- a/easyDataverse/dataverse.py +++ b/easyDataverse/dataverse.py @@ -226,11 +226,8 @@ def _version_is_compliant(self) -> bool: f"URL '{self.server_url}' is not a valid Dataverse installation. Couldn't find version info." ) - major, minor, *_ = response.json()["data"]["version"].split(".") - - # Remove all the non-numeric parts from the version string to avoid having leading 'v' or other characters. - major = "".join(filter(str.isdigit, major)) - minor = "".join(filter(str.isdigit, minor)) + version = response.json()["data"]["version"] + major, minor = self._extract_major_minor(version) if int(major) >= 6: return True @@ -239,6 +236,26 @@ def _version_is_compliant(self) -> bool: return False + @staticmethod + def _extract_major_minor(version: str) -> Tuple[int, int]: + """Extracts the major and minor version numbers from a Dataverse version string.""" + try: + major, minor, *_ = version.split(".") + major = "".join(filter(str.isdigit, major)) + minor = "".join(filter(str.isdigit, minor)) + return int(major), int(minor) + except ValueError: + raise ValueError(f"Version '{version}' is not a valid Dataverse version.") + + @staticmethod + def _check_version(major: int, minor: int) -> bool: + """Checks if the version is compliant.""" + if int(major) >= 6: + return True + elif int(major) >= 5 and int(minor) >= 13: + return True + return False + def _fetch_licenses(self) -> Dict[str, License]: """Fetches the licenses from the Dataverse installation.""" response = httpx.get(parse.urljoin(str(self.server_url), "/api/licenses")) diff --git a/tests/unit/test_dataverse.py b/tests/unit/test_dataverse.py index f5f2bb0..6074a98 100644 --- a/tests/unit/test_dataverse.py +++ b/tests/unit/test_dataverse.py @@ -21,3 +21,40 @@ def test_invalid_api_token(self): server_url="http://localhost:8080", api_token="not a uuid", ) + + @pytest.mark.unit + def test_valid_versions(self): + """Test that the version is compliant""" + cases = [ + "6.0", + "6.1", + "5.13", + "5.14", + "v6.0", + "v5.14", + "v5.13-beta", + "6.1.0", + ] + + for version in cases: + major, minor = Dataverse._extract_major_minor(version) + assert Dataverse._check_version(major, minor) + + @pytest.mark.unit + def test_invalid_version(self): + """Test that an invalid version raises a ValueError""" + with pytest.raises(ValueError): + Dataverse._extract_major_minor("not a version") + + @pytest.mark.unit + def test_unsupported_version(self): + """Test that the version is compliant""" + cases = [ + "4.0", + "4.1", + "5.12", + "5.11", + ] + for version in cases: + major, minor = Dataverse._extract_major_minor(version) + assert not Dataverse._check_version(major, minor) From cef327c8c9519b7a23cde499e2d340528d61b81c Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Wed, 18 Jun 2025 21:57:58 +0200 Subject: [PATCH 3/3] test borealis compliance --- tests/integration/test_connection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/integration/test_connection.py b/tests/integration/test_connection.py index dbd1b58..1b623d9 100644 --- a/tests/integration/test_connection.py +++ b/tests/integration/test_connection.py @@ -77,3 +77,8 @@ def test_numeric_namespace(self): Dataverse(server_url="https://dataverse.harvard.edu") except ValueError as e: AssertionError("Failed to parse numeric namespace: " + str(e)) + + @pytest.mark.integration + def test_version_borealis(self): + """Tests compatibility with BorealisData, which uses a different versioning scheme.""" + Dataverse("https://borealisdata.ca/")