diagnostics: Add tests for get_results

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2024-03-04 21:00:18 -05:00 committed by Sunil Mohan Adapa
parent 903059501f
commit dfaeadee6b
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -0,0 +1,58 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Tests for Diagnostics app functions."""
from collections import OrderedDict
from unittest.mock import patch
from plinth.app import App, Info
from plinth.modules.diagnostics import get_results
class AppTest(App):
"""Sample App for testing."""
app_id = 'test-app'
def __init__(self):
super().__init__()
info = Info('test-app', 1)
self.add(info)
def test_get_results():
"""Test getting the diagnostics results."""
var = 'plinth.modules.diagnostics.current_results'
with patch(var, {}):
assert get_results() == {'progress_percentage': 100, 'results': {}}
with patch(var, {
'apps': [],
'results': OrderedDict(),
'progress_percentage': 0
}):
assert get_results() == {
'apps': [],
'results': {},
'progress_percentage': 0
}
_ = AppTest()
results = OrderedDict({
'test-app': {
'id': 'test-app',
'diagnosis': [],
'exception': None,
'show_rerun_setup': False
}
})
with patch(
var, {
'apps': [('test-app', AppTest)],
'results': results,
'progress_percentage': 0
}):
results['test-app'].update({'name': 'test-app'})
assert get_results() == {
'apps': [('test-app', AppTest)],
'results': results,
'progress_percentage': 0
}