diff --git a/qubesappmenus/__init__.py b/qubesappmenus/__init__.py index 44b36ca..26eb4d8 100644 --- a/qubesappmenus/__init__.py +++ b/qubesappmenus/__init__.py @@ -60,7 +60,6 @@ class AppmenusExtension(qubes.ext.Extension): :type vm: qubes.vm.qubesvm.QubesVM """ - assert isinstance(vm, qubes.vm.qubesvm.QubesVM) if vm.updateable: return os.path.join(vm.dir_path, AppmenusSubdirs.templates_subdir) diff --git a/qubesappmenus/tests.py b/qubesappmenus/tests.py new file mode 100644 index 0000000..6a8e1d3 --- /dev/null +++ b/qubesappmenus/tests.py @@ -0,0 +1,157 @@ +#!/usr/bin/python2 +# coding=utf-8 +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2016 Marek Marczykowski-Górecki +# +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +# USA. +import os + +import unittest +import qubes +import qubes.tests +import qubesappmenus + + +class TestApp(object): + labels = {1: qubes.Label(1, '0xcc0000', 'red')} + + def __init__(self): + self.domains = {} + + +class TestVM(object): + # pylint: disable=too-few-public-methods + app = TestApp() + + def __init__(self, name, **kwargs): + self.running = False + self.installed_by_rpm = False + self.is_template = False + self.name = name + for k, v in kwargs.items(): + setattr(self, k, v) + + def is_running(self): + return self.running + + +class TC_00_Appmenus(qubes.tests.QubesTestCase): + """Unittests for appmenus, theoretically runnable from git checkout""" + def setUp(self): + super(TC_00_Appmenus, self).setUp() + vmname = qubes.tests.VMPREFIX + 'standalone' + self.standalone = TestVM( + name=vmname, + dir_path=os.path.join(qubes.config.qubes_base_dir, 'appvms', + vmname), + updateable=True, + ) + vmname = qubes.tests.VMPREFIX + 'template' + self.template = TestVM( + name=vmname, + dir_path=os.path.join( + qubes.config.qubes_base_dir, + 'vm-templates', vmname), + is_template=True, + updateable=True, + ) + vmname = qubes.tests.VMPREFIX + 'vm' + self.appvm = TestVM( + name=vmname, + dir_path=os.path.join( + qubes.config.qubes_base_dir, + 'appvms', vmname), + template=self.template, + updateable=False, + ) + self.app = TestApp() + self.ext = qubesappmenus.AppmenusExtension() + + def test_000_templates_dir(self): + self.assertEquals( + self.ext.templates_dir(self.standalone), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.standalone.name, 'apps.templates') + ) + self.assertEquals( + self.ext.templates_dir(self.template), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps.templates') + ) + self.assertEquals( + self.ext.templates_dir(self.appvm), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps.templates') + ) + + def test_001_template_icons_dir(self): + self.assertEquals( + self.ext.template_icons_dir(self.standalone), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.standalone.name, 'apps.tempicons') + ) + self.assertEquals( + self.ext.template_icons_dir(self.template), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps.tempicons') + ) + self.assertEquals( + self.ext.template_icons_dir(self.appvm), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps.tempicons') + ) + + def test_002_appmenus_dir(self): + self.assertEquals( + self.ext.appmenus_dir(self.standalone), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.standalone.name, 'apps') + ) + self.assertEquals( + self.ext.appmenus_dir(self.template), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps') + ) + self.assertEquals( + self.ext.appmenus_dir(self.appvm), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.appvm.name, 'apps') + ) + + def test_003_icons_dir(self): + self.assertEquals( + self.ext.icons_dir(self.standalone), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.standalone.name, 'apps.icons') + ) + self.assertEquals( + self.ext.icons_dir(self.template), + os.path.join(qubes.config.qubes_base_dir, 'vm-templates', + self.template.name, 'apps.icons') + ) + self.assertEquals( + self.ext.icons_dir(self.appvm), + os.path.join(qubes.config.qubes_base_dir, 'appvms', + self.appvm.name, 'apps.icons') + ) + +def list_tests(): + return ( + TC_00_Appmenus, + ) diff --git a/rpm_spec/core-dom0-linux.spec b/rpm_spec/core-dom0-linux.spec index 8876a55..5f7db50 100644 --- a/rpm_spec/core-dom0-linux.spec +++ b/rpm_spec/core-dom0-linux.spec @@ -215,6 +215,7 @@ chmod -x /etc/grub.d/10_linux %{python_sitelib}/qubeslinux-*.egg-info/* /usr/lib/python2.7/site-packages/qubesappmenus/__init__.py* /usr/lib/python2.7/site-packages/qubesappmenus/receive.py* +/usr/lib/python2.7/site-packages/qubesappmenus/tests.py* /etc/qubes-rpc/policy/qubes.SyncAppMenus /etc/qubes-rpc/qubes.SyncAppMenus /usr/libexec/qubes-appmenus/convert-apptemplate2vm.sh diff --git a/setup.py b/setup.py index 0c0416b..60f5486 100644 --- a/setup.py +++ b/setup.py @@ -21,5 +21,8 @@ if __name__ == '__main__': 'qubes.ext': [ 'qubesappmenus = qubesappmenus:AppmenusExtension' ], + 'qubes.tests.extra': [ + 'qubesappmenus = qubesappmenus.tests:list_tests', + ], } )