Skip to content

Commit

Permalink
Add pgrouting to check_versions command
Browse files Browse the repository at this point in the history
  • Loading branch information
justinefricou committed Nov 28, 2024
1 parent fd35a8c commit 5666992
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 12 additions & 1 deletion geotrek/common/management/commands/check_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@


class Command(BaseCommand):
help = "Check Geotrek-admin, Python, Django, PostgreSQL and PostGIS version used by your system."
help = "Check Geotrek-admin, Python, Django, PostgreSQL, PostGIS and pgRouting version used by your system."

def add_arguments(self, parser):
parser.add_argument('--geotrek', action='store_true', help="Show only Geotrek version.")
parser.add_argument('--python', action='store_true', help="Show only Python version.")
parser.add_argument('--django', action='store_true', help="Show only Django version.")
parser.add_argument('--postgresql', action='store_true', help="Show only PostgreSQL version.")
parser.add_argument('--postgis', action='store_true', help="Show only PostGIS version.")
parser.add_argument('--pgrouting', action='store_true', help="Show only pgRouting version.")
parser.add_argument('--full', action='store_true', help="Show full version infos.")

def get_geotrek_version(self):
Expand Down Expand Up @@ -49,6 +50,11 @@ def get_postgis_version(self, full=False):
cursor.execute("SELECT PostGIS_version()")
return cursor.fetchone()[0].split(' ')[0]

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

def handle(self, *args, **options):
full = options['full']

Expand All @@ -72,9 +78,14 @@ def handle(self, *args, **options):
self.stdout.write(self.get_postgis_version(full))
return

if options['pgrouting']:
self.stdout.write(self.get_pgrouting_version())
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())}")
return
11 changes: 9 additions & 2 deletions geotrek/common/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,25 @@ def test_postgis_version(self, mock_cursor):
call_command('check_versions', '--postgis', '--no-color', stdout=self.output)
self.assertEqual(self.output.getvalue().strip(), '3.1.0')

@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)']
call_command('check_versions', '--pgrouting', '--no-color', stdout=self.output)
self.assertEqual(self.output.getvalue().strip(), '2.6.3')

@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.return_value = ['14', '3.0']
mock_cursor.return_value.__enter__.return_value.fetchone.side_effect = [('14',), ('3.0',), ('(2.6.3,v2.6.3,b14f4d56b,master,1.67.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 : 14"
"PostGIS version : 3.0\n"
"pgRouting version : 2.6.3"
)
self.assertEqual(self.output.getvalue().strip(), expected_result)

0 comments on commit 5666992

Please sign in to comment.