Skip to content
Merged
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
23 changes: 22 additions & 1 deletion easyDataverse/dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +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(".")
version = response.json()["data"]["version"]
major, minor = self._extract_major_minor(version)

if int(major) >= 6:
return True
Expand All @@ -235,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"))
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
37 changes: 37 additions & 0 deletions tests/unit/test_dataverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)