#!/usr/bin/python2 -O
import sys
import unittest
import lxml.etree
sys.path.insert(0, '../')
import qubes.vm
class TestVM(qubes.vm.BaseVM):
testprop = qubes.vm.property('testprop')
testlabel = qubes.vm.property('testlabel')
defaultprop = qubes.vm.property('defaultprop', default='defaultvalue')
class TC_BaseVM(unittest.TestCase):
def setUp(self):
self.xml = lxml.etree.XML('''
testvalue
tagvalue
testservice
enabledservice
disabledservice
00:11.22
''')
def test_000_BaseVM_load(self):
node = self.xml.xpath('//domain')[0]
vm = TestVM(node)
self.assertEqual(vm.testprop, 'testvalue')
self.assertEqual(vm.testlabel, 'label-1')
self.assertEqual(vm.defaultprop, 'defaultvalue')
self.assertEqual(vm.tags, {'testtag': 'tagvalue'})
self.assertEqual(vm.devices, {'pci': ['00:11.22']})
self.assertEqual(vm.services, {
'testservice': True,
'enabledservice': True,
'disabledservice': False,
})
def test_001_BaseVM_nxproperty(self):
xml = lxml.etree.XML('''
nxvalue
''')
node = xml.xpath('//domain')[0]
def f():
vm = TestVM(node)
self.assertRaises(AttributeError, f)