From dfaeadee6bdbb8b5129f9c3c6612567563c8eef2 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Mon, 4 Mar 2024 21:00:18 -0500 Subject: [PATCH] diagnostics: Add tests for get_results Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- .../diagnostics/tests/test_diagnostics.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 plinth/modules/diagnostics/tests/test_diagnostics.py diff --git a/plinth/modules/diagnostics/tests/test_diagnostics.py b/plinth/modules/diagnostics/tests/test_diagnostics.py new file mode 100644 index 000000000..f056167aa --- /dev/null +++ b/plinth/modules/diagnostics/tests/test_diagnostics.py @@ -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 + }