Skip to content

Commit

Permalink
[req-change] Return "unspecified" when openwisp installation method i…
Browse files Browse the repository at this point in the history
…s not defined
  • Loading branch information
pandafy committed Apr 2, 2024
1 parent fde9d82 commit ece4c71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions openwisp_utils/admin_theme/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def get_installed_openwisp_packages():
}


def _get_openwisp2_detail(attribute_name):
def _get_openwisp2_detail(attribute_name, fallback=None):
try:
return import_string(f'openwisp2.{attribute_name}')
except ImportError:
return None
return fallback


def get_openwisp_version():
return _get_openwisp2_detail('__openwisp_version__')


def get_openwisp_installation_method():
return _get_openwisp2_detail('__openwisp_installation_method__')
return _get_openwisp2_detail('__openwisp_installation_method__', 'unspecified')


def get_enabled_openwisp_modules():
Expand Down
5 changes: 5 additions & 0 deletions openwisp_utils/measurements/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.test import TestCase, override_settings
from freezegun import freeze_time
from openwisp_utils import utils
from openwisp_utils.admin_theme import system_info
from urllib3.response import HTTPResponse

from .. import tasks
Expand Down Expand Up @@ -36,6 +37,10 @@ def setUp(self):
).replace(tzinfo=timezone.utc),
)

@patch.object(system_info, 'import_string', side_effect=ImportError)
def test_installation_method_not_defined(self, *args):
self.assertEqual(system_info.get_openwisp_installation_method(), 'unspecified')

def test_log_module_version_changes_on_new_installation(
self,
):
Expand Down

0 comments on commit ece4c71

Please sign in to comment.