mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-10 13:00:16 +02:00
Merge branch 'fix_admin_status_tags_bug' into 'master'
Bugfix: Loading of dashboard fails with 'NoneType object is not iterable' from status_tags See merge request allianceauth/allianceauth!1237
This commit is contained in:
commit
ddabb4539b
@ -83,9 +83,8 @@ class TestStatusOverviewTag(TestCase):
|
|||||||
}
|
}
|
||||||
mock_current_version_info.return_value = version_info
|
mock_current_version_info.return_value = version_info
|
||||||
mock_fetch_celery_queue_length.return_value = 3
|
mock_fetch_celery_queue_length.return_value = 3
|
||||||
|
|
||||||
context = {}
|
result = status_overview()
|
||||||
result = status_overview(context)
|
|
||||||
expected = {
|
expected = {
|
||||||
'notifications': GITHUB_NOTIFICATION_ISSUES[:5],
|
'notifications': GITHUB_NOTIFICATION_ISSUES[:5],
|
||||||
'latest_major': True,
|
'latest_major': True,
|
||||||
@ -128,6 +127,13 @@ class TestNotifications(TestCase):
|
|||||||
result = _current_notifications()
|
result = _current_notifications()
|
||||||
self.assertEqual(result['notifications'], list())
|
self.assertEqual(result['notifications'], list())
|
||||||
|
|
||||||
|
@patch(MODULE_PATH + '.admin_status.cache')
|
||||||
|
def test_current_notifications_is_none(self, mock_cache):
|
||||||
|
mock_cache.get_or_set.return_value = None
|
||||||
|
|
||||||
|
result = _current_notifications()
|
||||||
|
self.assertEqual(result['notifications'], list())
|
||||||
|
|
||||||
|
|
||||||
class TestCeleryQueueLength(TestCase):
|
class TestCeleryQueueLength(TestCase):
|
||||||
|
|
||||||
@ -170,6 +176,15 @@ class TestVersionTags(TestCase):
|
|||||||
result = _fetch_tags_from_gitlab()
|
result = _fetch_tags_from_gitlab()
|
||||||
self.assertEqual(result, GITHUB_TAGS)
|
self.assertEqual(result, GITHUB_TAGS)
|
||||||
|
|
||||||
|
@patch(MODULE_PATH + '.admin_status.__version__', TEST_VERSION)
|
||||||
|
@patch(MODULE_PATH + '.admin_status.cache')
|
||||||
|
def test_current_version_info_return_no_data(self, mock_cache):
|
||||||
|
mock_cache.get_or_set.return_value = None
|
||||||
|
|
||||||
|
expected = {}
|
||||||
|
result = _current_version_summary()
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
|
|
||||||
class TestLatestsVersion(TestCase):
|
class TestLatestsVersion(TestCase):
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL = (
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('allianceauth/admin-status/overview.html', takes_context=True)
|
@register.inclusion_tag('allianceauth/admin-status/overview.html')
|
||||||
def status_overview(context):
|
def status_overview() -> dict:
|
||||||
response = {
|
response = {
|
||||||
'notifications': list(),
|
'notifications': list(),
|
||||||
'current_version': __version__,
|
'current_version': __version__,
|
||||||
@ -46,7 +46,7 @@ def status_overview(context):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def _fetch_celery_queue_length():
|
def _fetch_celery_queue_length() -> int:
|
||||||
try:
|
try:
|
||||||
app = app_or_default(None)
|
app = app_or_default(None)
|
||||||
with app.connection_or_acquire() as conn:
|
with app.connection_or_acquire() as conn:
|
||||||
@ -69,11 +69,15 @@ def _current_notifications() -> dict:
|
|||||||
'gitlab_notification_issues',
|
'gitlab_notification_issues',
|
||||||
_fetch_notification_issues_from_gitlab,
|
_fetch_notification_issues_from_gitlab,
|
||||||
NOTIFICATION_CACHE_TIME
|
NOTIFICATION_CACHE_TIME
|
||||||
)
|
)
|
||||||
top_notifications = notifications[:5]
|
|
||||||
except requests.RequestException:
|
except requests.RequestException:
|
||||||
logger.exception('Error while getting gitlab notifications')
|
logger.exception('Error while getting gitlab notifications')
|
||||||
top_notifications = []
|
top_notifications = []
|
||||||
|
else:
|
||||||
|
if notifications:
|
||||||
|
top_notifications = notifications[:5]
|
||||||
|
else:
|
||||||
|
top_notifications = []
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'notifications': top_notifications,
|
'notifications': top_notifications,
|
||||||
@ -95,8 +99,15 @@ def _current_version_summary() -> dict:
|
|||||||
logger.exception('Error while getting gitlab release tags')
|
logger.exception('Error while getting gitlab release tags')
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
latest_major_version, latest_minor_version, latest_patch_version, latest_beta_version = \
|
if not tags:
|
||||||
_latests_versions(tags)
|
return {}
|
||||||
|
|
||||||
|
(
|
||||||
|
latest_major_version,
|
||||||
|
latest_minor_version,
|
||||||
|
latest_patch_version,
|
||||||
|
latest_beta_version
|
||||||
|
) = _latests_versions(tags)
|
||||||
current_version = Pep440Version(__version__)
|
current_version = Pep440Version(__version__)
|
||||||
|
|
||||||
has_latest_major = \
|
has_latest_major = \
|
||||||
@ -107,8 +118,8 @@ def _current_version_summary() -> dict:
|
|||||||
current_version >= latest_patch_version if latest_patch_version else False
|
current_version >= latest_patch_version if latest_patch_version else False
|
||||||
has_current_beta = \
|
has_current_beta = \
|
||||||
current_version.base_version <= latest_beta_version.base_version \
|
current_version.base_version <= latest_beta_version.base_version \
|
||||||
and latest_major_version.base_version <= latest_beta_version.base_version \
|
and latest_major_version.base_version <= latest_beta_version.base_version \
|
||||||
if latest_beta_version else False
|
if latest_beta_version else False
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'latest_major': has_latest_major,
|
'latest_major': has_latest_major,
|
||||||
@ -146,7 +157,6 @@ def _latests_versions(tags: list) -> tuple:
|
|||||||
else:
|
else:
|
||||||
versions.append(version)
|
versions.append(version)
|
||||||
|
|
||||||
|
|
||||||
latest_version = latest_patch_version = max(versions)
|
latest_version = latest_patch_version = max(versions)
|
||||||
latest_major_version = min([
|
latest_major_version = min([
|
||||||
v for v in versions if v.major == latest_version.major
|
v for v in versions if v.major == latest_version.major
|
||||||
@ -156,10 +166,15 @@ def _latests_versions(tags: list) -> tuple:
|
|||||||
if v.major == latest_version.major and v.minor == latest_version.minor
|
if v.major == latest_version.major and v.minor == latest_version.minor
|
||||||
])
|
])
|
||||||
latest_beta_version = max(betas)
|
latest_beta_version = max(betas)
|
||||||
return latest_major_version, latest_minor_version, latest_patch_version, latest_beta_version
|
return (
|
||||||
|
latest_major_version,
|
||||||
|
latest_minor_version,
|
||||||
|
latest_patch_version,
|
||||||
|
latest_beta_version
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES):
|
def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
|
||||||
"""returns a list from the GitLab API. Supports pageing"""
|
"""returns a list from the GitLab API. Supports pageing"""
|
||||||
result = list()
|
result = list()
|
||||||
for page in range(1, max_pages + 1):
|
for page in range(1, max_pages + 1):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user