Skip to content

Commit

Permalink
Use pgr_full_version for check_versions command
Browse files Browse the repository at this point in the history
  • Loading branch information
justinefricou committed Dec 2, 2024
1 parent c63c1a6 commit b1667a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions geotrek/common/management/commands/check_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ def get_postgis_version(self, full=False):
cursor.execute("SELECT PostGIS_version()")
return cursor.fetchone()[0].split(' ')[0]

def get_pgrouting_version(self):
def get_pgrouting_version(self, full=False):
with connection.cursor() as cursor:
cursor.execute("SELECT pgr_version()")
return cursor.fetchone()[0].split(' ')[0].strip('()').split(',')[0]
if full:
cursor.execute("SELECT pgr_full_version()")
return cursor.fetchone()[0]
else:
cursor.execute("SELECT pgr_version()")
return cursor.fetchone()[0].split(' ')[0]

def handle(self, *args, **options):
full = options['full']
Expand All @@ -79,13 +83,13 @@ def handle(self, *args, **options):
return

if options['pgrouting']:
self.stdout.write(self.get_pgrouting_version())
self.stdout.write(self.get_pgrouting_version(full))
return

self.stdout.write(f"Geotrek version : {self.style.SUCCESS(self.get_geotrek_version())}")
self.stdout.write(f"Python version : {self.style.SUCCESS(self.get_python_version(full))}")
self.stdout.write(f"Django version : {self.style.SUCCESS(self.get_django_version())}")
self.stdout.write(f"PostgreSQL version : {self.style.SUCCESS(self.get_postgresql_version(full))}")
self.stdout.write(f"PostGIS version : {self.style.SUCCESS(self.get_postgis_version(full))}")
self.stdout.write(f"pgRouting version : {self.style.SUCCESS(self.get_pgrouting_version())}")
self.stdout.write(f"pgRouting version : {self.style.SUCCESS(self.get_pgrouting_version(full))}")
return
8 changes: 4 additions & 4 deletions geotrek/common/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,23 @@ def test_postgis_version(self, mock_cursor):

@patch('django.db.connection.cursor')
def test_pgrouting_version(self, mock_cursor):
mock_cursor.return_value.__enter__.return_value.fetchone.return_value = ['(2.6.3,v2.6.3,b14f4d56b,master,1.67.0)']
mock_cursor.return_value.__enter__.return_value.fetchone.return_value = ['3.0.0']
call_command('check_versions', '--pgrouting', '--no-color', stdout=self.output)
self.assertEqual(self.output.getvalue().strip(), '2.6.3')
self.assertEqual(self.output.getvalue().strip(), '3.0.0')

@patch('geotrek.common.management.commands.check_versions.sys')
@patch('django.get_version', return_value='3.2.2')
@patch('django.db.connection.cursor')
def test_full_version(self, mock_cursor, mock_get_version, mock_version_info):
type(mock_version_info).version = PropertyMock(return_value="3.9.1")
mock_cursor.return_value.__enter__.return_value.fetchone.side_effect = [('14',), ('3.0',), ('(2.6.3,v2.6.3,b14f4d56b,master,1.67.0)',)]
mock_cursor.return_value.__enter__.return_value.fetchone.side_effect = [('14',), ('3.0',), ('3.0.0',)]
call_command('check_versions', '--full', '--no-color', stdout=self.output)
expected_result = (
f"Geotrek version : {__version__}\n"
"Python version : 3.9.1\n"
"Django version : 3.2.2\n"
"PostgreSQL version : 14\n"
"PostGIS version : 3.0\n"
"pgRouting version : 2.6.3"
"pgRouting version : 3.0.0"
)
self.assertEqual(self.output.getvalue().strip(), expected_result)

0 comments on commit b1667a8

Please sign in to comment.