label.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.values():
  29. self.assertNotIn(label.name, seen)
  30. seen.add(label.name)
  31. self.assertEqual(seen, set(['green', 'red', 'black']))
  32. def test_001_list_names(self):
  33. self.app.expected_calls[
  34. ('dom0', 'admin.label.List', None, None)] = \
  35. b'0\x00green\nred\nblack\n'
  36. seen = set()
  37. for label in self.app.labels:
  38. self.assertNotIn(label, seen)
  39. seen.add(label)
  40. self.assertEqual(seen, set(['green', 'red', 'black']))
  41. def test_002_list_keys(self):
  42. self.app.expected_calls[
  43. ('dom0', 'admin.label.List', None, None)] = \
  44. b'0\x00green\nred\nblack\n'
  45. seen = set()
  46. for label in self.app.labels.keys():
  47. self.assertNotIn(label, seen)
  48. seen.add(label)
  49. self.assertEqual(seen, set(['green', 'red', 'black']))
  50. def test_003_list_items(self):
  51. self.app.expected_calls[
  52. ('dom0', 'admin.label.List', None, None)] = \
  53. b'0\x00green\nred\nblack\n'
  54. seen = set()
  55. for name, label in self.app.labels.items():
  56. self.assertEqual(name, label.name)
  57. self.assertNotIn(name, seen)
  58. seen.add(name)
  59. self.assertEqual(seen, set(['green', 'red', 'black']))
  60. def test_010_get(self):
  61. self.app.expected_calls[
  62. ('dom0', 'admin.label.List', None, None)] = \
  63. b'0\x00green\nred\nblack\n'
  64. label = self.app.labels['green']
  65. self.assertIsInstance(label, Label)
  66. self.assertEqual(label.name, 'green')
  67. def test_011_get_color(self):
  68. self.app.expected_calls[
  69. ('dom0', 'admin.label.List', None, None)] = \
  70. b'0\x00green\nred\nblack\n'
  71. self.app.expected_calls[
  72. ('dom0', 'admin.label.Get', 'green', None)] = \
  73. b'0\x000x00FF00'
  74. label = self.app.labels['green']
  75. self.assertEqual(label.color, '0x00FF00')
  76. def test_012_get_index(self):
  77. self.app.expected_calls[
  78. ('dom0', 'admin.label.List', None, None)] = \
  79. b'0\x00green\nred\nblack\n'
  80. self.app.expected_calls[
  81. ('dom0', 'admin.label.Index', 'green', None)] = b'0\x003'
  82. label = self.app.labels['green']
  83. self.assertEqual(label.index, 3)
  84. def test_024_get_icon(self):
  85. self.app.expected_calls[
  86. ('dom0', 'admin.label.List', None, None)] = \
  87. b'0\x00green\nred\nblack\n'
  88. label = self.app.labels['green']
  89. self.assertEqual(label.icon, 'appvm-green')