1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 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
}
|