mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
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.
32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
from unittest.mock import patch
|
|
|
|
from computes.models import Compute
|
|
from django.contrib.auth import get_user_model
|
|
from django.contrib.messages import get_messages
|
|
from django.test import TestCase
|
|
from django.urls import reverse
|
|
from instances.models import Instance
|
|
|
|
|
|
class ChangeXmlTestCase(TestCase):
|
|
def setUp(self):
|
|
self.client.force_login(get_user_model().objects.create_superuser("xml_admin", "x@example.com", "pw"))
|
|
compute = Compute.objects.create(name="xml-compute", hostname="127.0.0.1", login="", password="", type=4)
|
|
self.instance = Instance.objects.create(compute=compute, name="xml-vm", uuid="11111111-2222-3333-4444-888888888888")
|
|
|
|
def post(self, status):
|
|
with patch("instances.models.wvmInstance") as wvm:
|
|
wvm.return_value.get_status.return_value = status
|
|
response = self.client.post(reverse("instances:change_xml", args=[self.instance.id]), {"inst_xml": "<domain/>"})
|
|
return response, wvm.return_value._defineXML
|
|
|
|
def test_shut_off_vm_gets_the_new_definition(self):
|
|
_, define = self.post(status=5)
|
|
define.assert_called_once_with("<domain/>")
|
|
|
|
def test_running_or_paused_vm_is_refused(self):
|
|
for status in (1, 3):
|
|
with self.subTest(status=status):
|
|
response, define = self.post(status)
|
|
define.assert_not_called()
|
|
self.assertIn("Power off", " ".join(str(m) for m in get_messages(response.wsgi_request)))
|