label.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. import qubesadmin.tests
  21. from qubesadmin.label import Label
  22. class TC_00_Label(qubesadmin.tests.QubesTestCase):
  23. def test_000_list(self):
  24. self.app.expected_calls[
  25. ('dom0', 'admin.label.List', None, None)] = \
  26. b'0\x00green\nred\nblack\n'
  27. seen = set()
  28. for label in self.app.labels:
  29. self.assertNotIn(label.name, seen)
  30. seen.add(label.name)
  31. self.assertEqual(seen, set(['green', 'red', 'black']))
  32. def test_010_get(self):
  33. self.app.expected_calls[
  34. ('dom0', 'admin.label.List', None, None)] = \
  35. b'0\x00green\nred\nblack\n'
  36. label = self.app.labels['green']
  37. self.assertIsInstance(label, Label)
  38. self.assertEqual(label.name, 'green')
  39. def test_011_get_color(self):
  40. self.app.expected_calls[
  41. ('dom0', 'admin.label.List', None, None)] = \
  42. b'0\x00green\nred\nblack\n'
  43. self.app.expected_calls[
  44. ('dom0', 'admin.label.Get', 'green', None)] = \
  45. b'0\x000x00FF00'
  46. label = self.app.labels['green']
  47. self.assertEqual(label.color, '0x00FF00')
  48. def test_012_get_index(self):
  49. self.app.expected_calls[
  50. ('dom0', 'admin.label.List', None, None)] = \
  51. b'0\x00green\nred\nblack\n'
  52. self.app.expected_calls[
  53. ('dom0', 'admin.label.Index', 'green', None)] = b'0\x003'
  54. label = self.app.labels['green']
  55. self.assertEqual(label.index, 3)
  56. def test_024_get_icon(self):
  57. self.app.expected_calls[
  58. ('dom0', 'admin.label.List', None, None)] = \
  59. b'0\x00green\nred\nblack\n'
  60. label = self.app.labels['green']
  61. self.assertEqual(label.icon, 'appvm-green')