Source code for qubesadmin.tests.tags

# -*- encoding: utf8 -*-
# The Qubes OS Project,
# Copyright (C) 2017 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
# 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, see <>.

import qubesadmin.tests
import qubesadmin.tags

[docs] class TC_00_Tags(qubesadmin.tests.QubesTestCase):
[docs] def setUp(self): super(TC_00_Tags, self).setUp()[('dom0', 'admin.vm.List', None, None)] = \ b'0\0test-vm class=AppVM state=Running\n' \ b'test-vm2 class=AppVM state=Running\n' \ b'test-vm3 class=AppVM state=Running\n' self.vm =['test-vm'] self.tags = qubesadmin.tags.Tags(self.vm)
[docs] def test_000_list(self):[ ('test-vm', 'admin.vm.tag.List', None, None)] = \ b'0\0tag1\ntag2\n' self.assertEqual(sorted(self.tags), ['tag1', 'tag2']) self.assertAllCalled()
[docs] def test_010_get(self):[ ('test-vm', 'admin.vm.tag.Get', 'tag1', None)] = \ b'0\x001' self.assertIn('tag1', self.tags) self.assertAllCalled()
[docs] def test_011_get_missing(self):[ ('test-vm', 'admin.vm.tag.Get', 'tag1', None)] = \ b'0\x000' self.assertNotIn('tag1', self.tags) self.assertAllCalled()
[docs] def test_020_set(self):[ ('test-vm', 'admin.vm.tag.Set', 'tag1', None)] = b'0\0' self.tags.add('tag1') self.assertAllCalled()
[docs] def test_030_update(self):[ ('test-vm', 'admin.vm.tag.Set', 'tag1', None)] = b'0\0'[ ('test-vm', 'admin.vm.tag.Set', 'tag2', None)] = b'0\0' self.tags.update(['tag1', 'tag2']) self.assertAllCalled()
[docs] def test_031_update_from_other(self):[ ('test-vm2', 'admin.vm.tag.List', None, None)] = \ b'0\0tag3\ntag4\n'[ ('test-vm', 'admin.vm.tag.Set', 'tag3', None)] = b'0\0'[ ('test-vm', 'admin.vm.tag.Set', 'tag4', None)] = b'0\0' self.tags.update(['test-vm2'].tags) self.assertAllCalled()
[docs] def test_040_remove(self):[ ('test-vm', 'admin.vm.tag.Remove', 'tag1', None)] = \ b'0\0' self.tags.remove('tag1') self.assertAllCalled()
[docs] def test_040_remove_missing(self):[ ('test-vm', 'admin.vm.tag.Remove', 'tag1', None)] = \ b'2\0QubesTagNotFoundError\0\0Tag not set for domain test-vm: ' \ b'tag1\0' with self.assertRaises(KeyError): self.tags.remove('tag1') self.assertAllCalled()
[docs] def test_050_discard(self):[ ('test-vm', 'admin.vm.tag.Remove', 'tag1', None)] = \ b'0\0' self.tags.discard('tag1') self.assertAllCalled()
[docs] def test_051_discard_missing(self):[ ('test-vm', 'admin.vm.tag.Remove', 'tag1', None)] = \ b'2\0QubesTagNotFoundError\0\0Tag not set for domain test-vm: ' \ b'tag1\0' self.tags.discard('tag1') self.assertAllCalled()