qubesvm.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/python2 -O
  2. # vim: fileencoding=utf-8
  3. # pylint: disable=protected-access
  4. #
  5. # The Qubes OS Project, https://www.qubes-os.org/
  6. #
  7. # Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  8. # Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. #
  24. import unittest
  25. import qubes
  26. import qubes.config
  27. import qubes.vm.qubesvm
  28. import qubes.tests
  29. class TestProp(object):
  30. # pylint: disable=too-few-public-methods
  31. __name__ = 'testprop'
  32. class TestVM(object):
  33. # pylint: disable=too-few-public-methods
  34. def __init__(self):
  35. self.running = False
  36. self.installed_by_rpm = False
  37. def is_running(self):
  38. return self.running
  39. class TC_00_setters(qubes.tests.QubesTestCase):
  40. def setUp(self):
  41. self.vm = TestVM()
  42. self.prop = TestProp()
  43. def test_000_setter_qid(self):
  44. self.assertEqual(
  45. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
  46. def test_001_setter_qid_lt_0(self):
  47. with self.assertRaises(ValueError):
  48. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
  49. def test_002_setter_qid_gt_max(self):
  50. with self.assertRaises(ValueError):
  51. qubes.vm.qubesvm._setter_qid(self.vm,
  52. self.prop, qubes.config.max_qid + 5)
  53. def test_010_setter_name(self):
  54. self.assertEqual(
  55. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
  56. 'test_name-1')
  57. def test_011_setter_name_longer_than_31(self):
  58. # pylint: disable=invalid-name
  59. with self.assertRaises(ValueError):
  60. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
  61. def test_012_setter_name_illegal_character(self):
  62. # pylint: disable=invalid-name
  63. with self.assertRaises(ValueError):
  64. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
  65. def test_013_setter_name_first_not_letter(self):
  66. # pylint: disable=invalid-name
  67. with self.assertRaises(ValueError):
  68. qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
  69. def test_014_setter_name_running(self):
  70. self.vm.running = True
  71. with self.assertRaises(qubes.QubesException):
  72. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  73. def test_015_setter_name_installed_by_rpm(self):
  74. # pylint: disable=invalid-name
  75. self.vm.installed_by_rpm = True
  76. with self.assertRaises(qubes.QubesException):
  77. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  78. @unittest.skip('test not implemented')
  79. def test_020_setter_kernel(self):
  80. pass
  81. class TC_90_QubesVM(qubes.tests.QubesTestCase):
  82. @unittest.skip('test not implemented')
  83. def test_000_init(self):
  84. pass