Skip to content

Commit

Permalink
Merge pull request #768 from neo4j-contrib/bug/aura-version-check
Browse files Browse the repository at this point in the history
Fix aura version check
  • Loading branch information
mariusconjeaud authored Dec 8, 2023
2 parents 10c5898 + 9cb0ac1 commit 300402f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions neomodel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,19 @@ def version_tag_to_integer(version_tag):
"""
Converts a version string to an integer representation to allow for quick comparisons between versions.
:param a_version_string: The version string to be converted (e.g. '3.4.0')
:param a_version_string: The version string to be converted (e.g. '5.4.0')
:type a_version_string: str
:return: An integer representation of the version string (e.g. '3.4.0' --> 340)
:return: An integer representation of the version string (e.g. '5.4.0' --> 50400)
:rtype: int
"""
components = version_tag.split(".")
while len(components) < 3:
components.append("0")
num = 0
for index, component in enumerate(components):
num += (10 ** ((len(components) - 1) - index)) * int(component)
# Aura started adding a -aura suffix in version numbers, like "5.14-aura"
# This will strip the suffix to allow for proper comparison : 14 instead of 14-aura
if "-" in component:
component = component.split("-")[0]
num += (100 ** ((len(components) - 1) - index)) * int(component)
return num
10 changes: 10 additions & 0 deletions test/test_dbms_awareness.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pytest import mark

from neomodel import db
from neomodel.util import version_tag_to_integer


@mark.skipif(
Expand All @@ -9,6 +10,7 @@
def test_version_awareness():
assert db.database_version == "5.7.0"
assert db.version_is_higher_than("5.7")
assert db.version_is_higher_than("5.6.0")
assert db.version_is_higher_than("5")
assert db.version_is_higher_than("4")

Expand All @@ -20,3 +22,11 @@ def test_edition_awareness():
assert db.edition_is_enterprise()
else:
assert not db.edition_is_enterprise()


def test_version_tag_to_integer():
assert version_tag_to_integer("5.7.1") == 50701
assert version_tag_to_integer("5.1") == 50100
assert version_tag_to_integer("5") == 50000
assert version_tag_to_integer("5.14.1") == 51401
assert version_tag_to_integer("5.14-aura") == 51400

0 comments on commit 300402f

Please sign in to comment.