|
| 1 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | +# *************************************************************************** |
| 3 | +# * * |
| 4 | +# * Copyright (c) 2025 The FreeCAD project association AISBL * |
| 5 | +# * * |
| 6 | +# * This file is part of the FreeCAD Addon Manager. * |
| 7 | +# * * |
| 8 | +# * FreeCAD is free software: you can redistribute it and/or modify it * |
| 9 | +# * under the terms of the GNU Lesser General Public License as * |
| 10 | +# * published by the Free Software Foundation, either version 2.1 of the * |
| 11 | +# * License, or (at your option) any later version. * |
| 12 | +# * * |
| 13 | +# * FreeCAD is distributed in the hope that it will be useful, but * |
| 14 | +# * WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 | +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 16 | +# * Lesser General Public License for more details. * |
| 17 | +# * * |
| 18 | +# * You should have received a copy of the GNU Lesser General Public * |
| 19 | +# * License along with FreeCAD. If not, see * |
| 20 | +# * <https://www.gnu.org/licenses/>. * |
| 21 | +# * * |
| 22 | +# *************************************************************************** |
| 23 | + |
| 24 | +"""Tests for the PackageDetailsView widget. Many tests are currently just stubs that ensure the |
| 25 | +code paths are executed so that the CI can find any errors in Python or Qt5/Qt6 compatibility. |
| 26 | +""" |
| 27 | + |
| 28 | +import unittest |
| 29 | +from unittest.mock import patch |
| 30 | + |
| 31 | +from PySideWrapper import QtWidgets |
| 32 | + |
| 33 | +from Widgets.addonmanager_widget_package_details_view import ( |
| 34 | + PackageDetailsView, |
| 35 | + UpdateInformation, |
| 36 | + WarningFlags, |
| 37 | +) |
| 38 | + |
| 39 | + |
| 40 | +class TestPackageDetailsView(unittest.TestCase): |
| 41 | + |
| 42 | + def setUp(self): |
| 43 | + self.window = QtWidgets.QDialog() |
| 44 | + self.window.setObjectName("Test Widget Package Details View Window") |
| 45 | + self.pdv = PackageDetailsView(self.window) |
| 46 | + |
| 47 | + def tearDown(self): |
| 48 | + self.window.close() |
| 49 | + del self.window |
| 50 | + |
| 51 | + def test_instantiation(self): |
| 52 | + self.assertIsInstance(self.pdv, PackageDetailsView) |
| 53 | + |
| 54 | + def test_set_location_to_empty(self): |
| 55 | + """When location is set empty, the location display is hidden""" |
| 56 | + self.pdv.set_location(None) |
| 57 | + self.assertTrue(self.pdv.location_label.isHidden()) |
| 58 | + |
| 59 | + def test_set_location_to_nonempty(self): |
| 60 | + """When location is set to a string, the display is shown""" |
| 61 | + self.pdv.set_location("test") |
| 62 | + self.assertFalse(self.pdv.location_label.isHidden()) |
| 63 | + self.assertIn("test", self.pdv.location_label.text()) |
| 64 | + |
| 65 | + def test_set_url_to_empty(self): |
| 66 | + """When URL is set empty, the URL display is hidden""" |
| 67 | + self.pdv.set_url(None) |
| 68 | + self.assertTrue(self.pdv.url_label.isHidden()) |
| 69 | + |
| 70 | + def test_set_url_to_nonempty(self): |
| 71 | + """When URL is set to a string, the URL display is shown""" |
| 72 | + self.pdv.set_url("test") |
| 73 | + self.assertFalse(self.pdv.url_label.isHidden()) |
| 74 | + self.assertIn("test", self.pdv.url_label.text()) |
| 75 | + |
| 76 | + def test_set_installed_minimal(self): |
| 77 | + """Exercise the set_installed method with the minimum arguments""" |
| 78 | + self.pdv.set_installed(True) |
| 79 | + |
| 80 | + def test_set_installed_full(self): |
| 81 | + """Exercise the set_installed method with all arguments""" |
| 82 | + self.pdv.set_installed(True, 1234567.89, "version", "branch") |
| 83 | + |
| 84 | + @patch("Widgets.addonmanager_widget_package_details_view.PackageDetailsView.set_location") |
| 85 | + def test_set_installed_false(self, mock_set_location): |
| 86 | + """When the package is not installed, the location label is un-set""" |
| 87 | + self.pdv.set_installed(False) |
| 88 | + mock_set_location.assert_called_with(None) |
| 89 | + |
| 90 | + def test_set_update_available_true(self): |
| 91 | + """Not exhaustive, just test the basic call with update available=True""" |
| 92 | + self.pdv.set_update_available(UpdateInformation(update_available=True)) |
| 93 | + |
| 94 | + def test_set_update_available_false(self): |
| 95 | + """Not exhaustive, just test the basic call with update_available=False""" |
| 96 | + self.pdv.set_update_available(UpdateInformation(update_available=False)) |
| 97 | + |
| 98 | + def test_set_disabled_true(self): |
| 99 | + self.pdv.set_disabled(True) |
| 100 | + |
| 101 | + def test_set_disabled_false(self): |
| 102 | + self.pdv.set_disabled(True) |
| 103 | + |
| 104 | + def test_allow_disabling_true(self): |
| 105 | + self.pdv.allow_disabling(True) |
| 106 | + |
| 107 | + def test_allow_disabling_false(self): |
| 108 | + self.pdv.allow_disabling(False) |
| 109 | + |
| 110 | + def test_allow_running_true(self): |
| 111 | + self.pdv.allow_running(True) |
| 112 | + |
| 113 | + def test_allow_running_false(self): |
| 114 | + self.pdv.allow_running(False) |
| 115 | + |
| 116 | + def test_set_warning_flags_obsolete(self): |
| 117 | + self.pdv.set_warning_flags(WarningFlags(obsolete=True)) |
| 118 | + |
| 119 | + def test_set_warning_flags_py2(self): |
| 120 | + self.pdv.set_warning_flags(WarningFlags(python2=True)) |
| 121 | + |
| 122 | + def test_set_warning_flags_freecad_version(self): |
| 123 | + self.pdv.set_warning_flags(WarningFlags(required_freecad_version="99.0")) |
| 124 | + |
| 125 | + def test_set_warning_flags_non_osi_approved(self): |
| 126 | + self.pdv.set_warning_flags(WarningFlags(non_osi_approved=True)) |
| 127 | + |
| 128 | + def test_set_warning_flags_non_fsf_libre(self): |
| 129 | + self.pdv.set_warning_flags(WarningFlags(non_fsf_libre=True)) |
| 130 | + |
| 131 | + def test_set_new_disabled_status_true(self): |
| 132 | + self.pdv.set_new_disabled_status(True) |
| 133 | + |
| 134 | + def test_set_new_disabled_status_false(self): |
| 135 | + self.pdv.set_new_disabled_status(False) |
| 136 | + |
| 137 | + def test_set_new_branch(self): |
| 138 | + self.pdv.set_new_branch("test") |
| 139 | + |
| 140 | + def test_set_updated(self): |
| 141 | + self.pdv.set_updated() |
0 commit comments