mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
test: each app keeps its tests in a tests package
131 test modules sat next to the code they test; instances alone had 51 of them beside views.py and utils.py. They move into a tests/ package per app, and the JavaScript checks into webvirtcloud/tests/js. Each non-empty tests.py becomes tests/test_views.py; the empty generated stubs are removed. Imports of the app's own modules become absolute, paths built from __file__ go one level up, the live helper is instances.tests.livetest, and coverage omits */tests/*. The suite discovers the same 960 tests as before.
This commit is contained in:
parent
0906838193
commit
c55f52f025
154 changed files with 27 additions and 39 deletions
45
vrtManager/tests/test_resize_disk.py
Normal file
45
vrtManager/tests/test_resize_disk.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(MAC_OUI="52:54:10")
|
||||
|
||||
from libvirt import VIR_DOMAIN_BLOCK_RESIZE_BYTES, VIR_STORAGE_VOL_BLOCK, VIR_STORAGE_VOL_FILE
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
SIZE = 10 << 30
|
||||
|
||||
|
||||
def vm(active, vol_type):
|
||||
inst = wvmInstance.__new__(wvmInstance)
|
||||
inst.instance = MagicMock()
|
||||
inst.instance.isActive.return_value = active
|
||||
vol = MagicMock()
|
||||
vol.info.return_value = [vol_type, 0, 0]
|
||||
inst.get_volume_by_path = MagicMock(return_value=vol)
|
||||
inst.resize_disk([{"path": "/dev/vg/disk", "size_new": SIZE}])
|
||||
return inst, vol
|
||||
|
||||
|
||||
class ResizeDiskTestCase(unittest.TestCase):
|
||||
def test_running_block_volume_grows_in_the_pool_then_in_qemu(self):
|
||||
inst, vol = vm(active=True, vol_type=VIR_STORAGE_VOL_BLOCK)
|
||||
vol.resize.assert_called_once_with(SIZE)
|
||||
inst.instance.blockResize.assert_called_once_with("/dev/vg/disk", SIZE, VIR_DOMAIN_BLOCK_RESIZE_BYTES)
|
||||
|
||||
def test_running_image_file_grows_through_qemu_only(self):
|
||||
# qemu-img cannot take the image lock QEMU holds
|
||||
inst, vol = vm(active=True, vol_type=VIR_STORAGE_VOL_FILE)
|
||||
vol.resize.assert_not_called()
|
||||
inst.instance.blockResize.assert_called_once()
|
||||
|
||||
def test_stopped_vm_grows_the_volume(self):
|
||||
inst, vol = vm(active=False, vol_type=VIR_STORAGE_VOL_FILE)
|
||||
vol.resize.assert_called_once_with(SIZE)
|
||||
inst.instance.blockResize.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue