qubesvm.py 3.1 KB

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