appmenus: add simple unit tests

QubesOS/qubes-issues#1897
This commit is contained in:
Marek Marczykowski-Górecki 2016-04-07 17:13:58 +02:00
parent acee13bf53
commit c32fbe14aa
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 161 additions and 1 deletions

View File

@ -60,7 +60,6 @@ class AppmenusExtension(qubes.ext.Extension):
:type vm: qubes.vm.qubesvm.QubesVM :type vm: qubes.vm.qubesvm.QubesVM
""" """
assert isinstance(vm, qubes.vm.qubesvm.QubesVM)
if vm.updateable: if vm.updateable:
return os.path.join(vm.dir_path, return os.path.join(vm.dir_path,
AppmenusSubdirs.templates_subdir) AppmenusSubdirs.templates_subdir)

157
qubesappmenus/tests.py Normal file
View File

@ -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
# <marmarek@invisiblethingslab.com>
#
# 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,
)

View File

@ -215,6 +215,7 @@ chmod -x /etc/grub.d/10_linux
%{python_sitelib}/qubeslinux-*.egg-info/* %{python_sitelib}/qubeslinux-*.egg-info/*
/usr/lib/python2.7/site-packages/qubesappmenus/__init__.py* /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/receive.py*
/usr/lib/python2.7/site-packages/qubesappmenus/tests.py*
/etc/qubes-rpc/policy/qubes.SyncAppMenus /etc/qubes-rpc/policy/qubes.SyncAppMenus
/etc/qubes-rpc/qubes.SyncAppMenus /etc/qubes-rpc/qubes.SyncAppMenus
/usr/libexec/qubes-appmenus/convert-apptemplate2vm.sh /usr/libexec/qubes-appmenus/convert-apptemplate2vm.sh

View File

@ -21,5 +21,8 @@ if __name__ == '__main__':
'qubes.ext': [ 'qubes.ext': [
'qubesappmenus = qubesappmenus:AppmenusExtension' 'qubesappmenus = qubesappmenus:AppmenusExtension'
], ],
'qubes.tests.extra': [
'qubesappmenus = qubesappmenus.tests:list_tests',
],
} }
) )