qubesvm.py 3.4 KB

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