qubesvm.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.exc
  27. import qubes.config
  28. import qubes.vm.qubesvm
  29. import qubes.tests
  30. class TestProp(object):
  31. # pylint: disable=too-few-public-methods
  32. __name__ = 'testprop'
  33. class TestVM(object):
  34. # pylint: disable=too-few-public-methods
  35. def __init__(self):
  36. self.running = False
  37. self.installed_by_rpm = False
  38. def is_running(self):
  39. return self.running
  40. class TC_00_setters(qubes.tests.QubesTestCase):
  41. def setUp(self):
  42. self.vm = TestVM()
  43. self.prop = TestProp()
  44. def test_000_setter_qid(self):
  45. self.assertEqual(
  46. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
  47. def test_001_setter_qid_lt_0(self):
  48. with self.assertRaises(ValueError):
  49. qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
  50. def test_002_setter_qid_gt_max(self):
  51. with self.assertRaises(ValueError):
  52. qubes.vm.qubesvm._setter_qid(self.vm,
  53. self.prop, qubes.config.max_qid + 5)
  54. def test_010_setter_name(self):
  55. self.assertEqual(
  56. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
  57. 'test_name-1')
  58. def test_011_setter_name_longer_than_31(self):
  59. # pylint: disable=invalid-name
  60. with self.assertRaises(ValueError):
  61. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
  62. def test_012_setter_name_illegal_character(self):
  63. # pylint: disable=invalid-name
  64. with self.assertRaises(ValueError):
  65. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
  66. def test_013_setter_name_first_not_letter(self):
  67. # pylint: disable=invalid-name
  68. with self.assertRaises(ValueError):
  69. qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
  70. def test_014_setter_name_running(self):
  71. self.vm.running = True
  72. with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
  73. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  74. def test_015_setter_name_installed_by_rpm(self):
  75. # pylint: disable=invalid-name
  76. self.vm.installed_by_rpm = True
  77. with self.assertRaises(qubes.exc.QubesException):
  78. qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
  79. @unittest.skip('test not implemented')
  80. def test_020_setter_kernel(self):
  81. pass
  82. class TC_90_QubesVM(qubes.tests.QubesTestCase):
  83. @unittest.skip('test not implemented')
  84. def test_000_init(self):
  85. pass