tests: add/fix VM state tests

This commit is contained in:
Marek Marczykowski-Górecki 2017-04-15 14:23:22 +02:00
parent 914c2d7e5e
commit 7a4f36f015
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 40 additions and 8 deletions

View File

@ -24,7 +24,7 @@ import qubesmgmt.tests
class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase):
def test_000_list(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=running\n'
b'0\x00test-vm class=AppVM state=Running\n'
self.assertEqual(
list(self.app.domains.keys()),
['test-vm'])
@ -32,7 +32,7 @@ class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase):
def test_001_getitem(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=running\n'
b'0\x00test-vm class=AppVM state=Running\n'
try:
vm = self.app.domains['test-vm']
self.assertEqual(vm.name, 'test-vm')
@ -46,7 +46,7 @@ class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase):
def test_002_in(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=running\n'
b'0\x00test-vm class=AppVM state=Running\n'
self.assertIn('test-vm', self.app.domains)
self.assertAllCalled()
@ -55,7 +55,7 @@ class TC_00_VMCollection(qubesmgmt.tests.QubesTestCase):
def test_003_iter(self):
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=running\n'
b'0\x00test-vm class=AppVM state=Running\n'
self.assertEqual([vm.name for vm in self.app.domains], ['test-vm'])
self.assertAllCalled()

View File

@ -147,7 +147,7 @@ class TC_90_List_with_qubesd_calls(qubesmgmt.tests.QubesTestCase):
qubesmgmt.tools.qvm_ls.main([], app=self.app)
self.assertEqual(stdout.getvalue(),
'NAME STATUS LABEL TEMPLATE NETVM\n'
'sys-net a--N---- red template1 sys-net\n'
'sys-net ar-N---- red template1 sys-net\n'
'template1 t-U----- black - sys-net\n'
'vm1 a------- green template1 sys-net\n')
'vm1 ar------ green template1 sys-net\n')
self.assertAllCalled()

View File

@ -25,5 +25,5 @@ class VMTestCase(qubesmgmt.tests.QubesTestCase):
def setUp(self):
super(VMTestCase, self).setUp()
self.app.expected_calls[('dom0', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=running\n'
b'0\x00test-vm class=AppVM state=Running\n'
self.vm = self.app.domains['test-vm']

View File

@ -18,7 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
import qubesmgmt.tests
import qubesmgmt.tests.vm
class TC_00_Properties(qubesmgmt.tests.vm.VMTestCase):
@ -177,3 +177,35 @@ class TC_01_SpecialCases(qubesmgmt.tests.vm.VMTestCase):
('test-vm', 'mgmt.vm.property.Set', 'name', b'test-vm2')]
vm = self.app.domains['test-vm']
self.assertAllCalled()
def test_010_power_state_running(self):
self.app.expected_calls[('test-vm', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Running\n'
self.assertEqual(self.vm.get_power_state(), 'Running')
self.assertTrue(self.vm.is_running())
self.assertFalse(self.vm.is_halted())
self.assertFalse(self.vm.is_paused())
def test_011_power_state_paused(self):
self.app.expected_calls[('test-vm', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Paused\n'
self.assertEqual(self.vm.get_power_state(), 'Paused')
self.assertTrue(self.vm.is_running())
self.assertFalse(self.vm.is_halted())
self.assertTrue(self.vm.is_paused())
def test_012_power_state_halted(self):
self.app.expected_calls[('test-vm', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Halted\n'
self.assertEqual(self.vm.get_power_state(), 'Halted')
self.assertFalse(self.vm.is_running())
self.assertTrue(self.vm.is_halted())
self.assertFalse(self.vm.is_paused())
def test_012_power_state_transient(self):
self.app.expected_calls[('test-vm', 'mgmt.vm.List', None, None)] = \
b'0\x00test-vm class=AppVM state=Transient\n'
self.assertEqual(self.vm.get_power_state(), 'Transient')
self.assertTrue(self.vm.is_running())
self.assertFalse(self.vm.is_halted())
self.assertFalse(self.vm.is_paused())