1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +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:
catborise 2026-10-12 10:37:29 +03:00
parent 0906838193
commit c55f52f025
154 changed files with 27 additions and 39 deletions

View file

@ -634,7 +634,7 @@ python manage.py test # all tests, including vrtManager
ruff check .
```
The suite includes mocked regression tests and disk/clone tests on libvirt's in-process `test:///default` driver. Set `WEBVIRTCLOUD_DB_HOST` (and the other `WEBVIRTCLOUD_DB_*` variables) to run it against PostgreSQL, as CI does.
Each app keeps its tests in a `tests/` package, so `python manage.py test instances` runs one app. The suite includes mocked regression tests and disk/clone tests on libvirt's in-process `test:///default` driver. Set `WEBVIRTCLOUD_DB_HOST` (and the other `WEBVIRTCLOUD_DB_*` variables) to run it against PostgreSQL, as CI does.
The compute tests try a local libvirt and skip when none answers; the instance tests run only when `TEST_LIBVIRT_HOST` is set. A green result with skips does not establish live KVM compatibility. The instance tests create `wvc-test-*` VMs and a temporary `wvc-test` pool (`/var/lib/libvirt/wvc-test`), remove them afterwards, and fail if any other VM or volume on the host changed:

View file

0
admin/tests/__init__.py Normal file
View file

View file

@ -1,2 +0,0 @@
# Create your tests here.

View file

View file

View file

@ -4,7 +4,7 @@ from django.shortcuts import reverse
from django.test import RequestFactory, TestCase, TransactionTestCase
from vrtManager.connection import CONN_SOCKET, connection_manager
from .models import Compute
from computes.models import Compute
TEST_COMPUTE_HOST = os.environ.get("TEST_LIBVIRT_HOST", "localhost")
TEST_COMPUTE_LOGIN = os.environ.get("TEST_LIBVIRT_LOGIN", "")

View file

View file

@ -16,7 +16,7 @@ try:
except ImportError: # pragma: no cover
socketio = None
ROOT = Path(__file__).resolve().parent.parent
ROOT = Path(__file__).resolve().parent.parent.parent
SOCKETIOD = ROOT / "console" / "socketiod"

View file

@ -5,7 +5,7 @@ import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
ROOT = Path(__file__).resolve().parent.parent.parent
SOCKETIOD = ROOT / "console" / "socketiod"

View file

@ -16,7 +16,7 @@ from instances.models import Instance
from libvirt import libvirtError
# Dynamically load console/novncd script for testing
NOVNCD_PATH = str(Path(__file__).resolve().parent / "novncd")
NOVNCD_PATH = str(Path(__file__).resolve().parent.parent / "novncd")
_loader = importlib.machinery.SourceFileLoader("novncd_mod", NOVNCD_PATH)
_spec = importlib.util.spec_from_file_location(
"novncd_mod", NOVNCD_PATH, loader=_loader

View file

@ -1,2 +0,0 @@
# Create your tests here.

View file

View file

View file

@ -8,7 +8,7 @@ import time
import unittest
from pathlib import Path
GSTFSD = Path(__file__).resolve().parent.parent / "conf" / "daemon" / "gstfsd"
GSTFSD = Path(__file__).resolve().parent.parent.parent / "conf" / "daemon" / "gstfsd"
# A stand-in for libguestfs: the guest's operating systems ("roots", each with
# its mountpoints), its files, and what is mounted live in a JSON file.

View file

@ -1,6 +1,6 @@
"""Live checks that a failed VM creation leaves no volumes behind.
Runs only with TEST_LIBVIRT_HOST set (see instances/livetest.py).
Runs only with TEST_LIBVIRT_HOST set (see instances/tests/livetest.py).
"""
import os

View file

@ -3,7 +3,7 @@
Each test asserts the safe behavior. Known unfixed cases are marked
expectedFailure; a fix turns them into unexpected successes, which fail
the run until the marker is removed. Runs only with
TEST_LIBVIRT_HOST set (see instances/livetest.py).
TEST_LIBVIRT_HOST set (see instances/tests/livetest.py).
"""
import os
@ -18,8 +18,8 @@ from django.urls import reverse
from vrtManager.connection import connection_manager
from . import livetest
from .models import Instance
from .utils import refr
from instances.models import Instance
from instances.utils import refr
P = livetest.PREFIX

View file

@ -2,7 +2,7 @@
QEMU holds a running domain's image, so the size goes through blockResize;
the guest and the volume must both see it, and the persistent definition
stays as it was. Runs only with TEST_LIBVIRT_HOST set (see instances/livetest.py).
stays as it was. Runs only with TEST_LIBVIRT_HOST set (see instances/tests/livetest.py).
"""
import os

View file

@ -6,7 +6,7 @@ with qemu-guest-agent enabled.
The tests boot wvc-test VMs from qcow2 overlays in the test pool, so the
image itself is only read. They are skipped while a running VM uses the
image, since its content would change under the overlays. Runs only with TEST_LIBVIRT_HOST set as well (see
instances/livetest.py).
instances/tests/livetest.py).
"""
import json
@ -24,8 +24,8 @@ from lxml import etree
from vrtManager.connection import connection_manager
from . import livetest
from .models import Instance
from .utils import refr
from instances.models import Instance
from instances.utils import refr
P = livetest.PREFIX
BOOT_TIMEOUT = 300

View file

@ -2,7 +2,7 @@
Every edit that redefines the domain must start from the persistent
definition with secrets (VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE).
Runs only with TEST_LIBVIRT_HOST set (see instances/livetest.py).
Runs only with TEST_LIBVIRT_HOST set (see instances/tests/livetest.py).
"""
import os

View file

@ -5,7 +5,7 @@ before and after. The edit must show its effect, and once the nodes it is
allowed to touch are removed from both sides, the rest of the definition
must be identical: unknown elements, secrets and pending changes survive.
On a running VM, edits of the persistent definition must leave the live
one alone. Runs only with TEST_LIBVIRT_HOST set (see instances/livetest.py).
one alone. Runs only with TEST_LIBVIRT_HOST set (see instances/tests/livetest.py).
"""
import os

View file

@ -14,8 +14,8 @@ from vrtManager.create import wvmCreate
from vrtManager.util import randomUUID
from . import livetest
from .models import Flavor, Instance
from .utils import refr
from instances.models import Flavor, Instance
from instances.utils import refr
TEST_COMPUTE_HOST = os.environ.get("TEST_LIBVIRT_HOST", "localhost")
TEST_COMPUTE_LOGIN = os.environ.get("TEST_LIBVIRT_LOGIN", "")

View file

@ -15,7 +15,7 @@ from accounts.models import UserInstance, UserSSHKey
from computes.models import Compute
from instances.models import Instance
ROOT = Path(__file__).resolve().parent.parent
ROOT = Path(__file__).resolve().parent.parent.parent
PAYLOAD = "<script>alert(1)</script>"

View file

@ -1,2 +0,0 @@
# Create your tests here.

View file

Some files were not shown because too many files have changed in this diff Show more