diff --git a/instances/tests/test_create_instance.py b/instances/tests/test_create_instance.py index 5fb029aa..658bd54e 100644 --- a/instances/tests/test_create_instance.py +++ b/instances/tests/test_create_instance.py @@ -5,7 +5,7 @@ from unittest.mock import MagicMock, patch from computes.models import Compute from django.contrib.auth import get_user_model -from django.test import TestCase +from django.test import SimpleTestCase, TestCase from django.urls import reverse from instances.api.serializers import CreateInstanceSerializer from instances.models import Instance @@ -164,7 +164,7 @@ class CreateInstanceViewTests(TestCase): conn.get_firmwares.assert_called_once_with("x86_64", "q35") -class NicMacsTestCase(TestCase): +class NicMacsTestCase(SimpleTestCase): def test_macs_follow_the_networks(self): self.assertEqual(nic_macs("52:54:00:00:00:01", "a,b"), ["52:54:00:00:00:01"]) self.assertEqual(nic_macs("", "a,b"), []) diff --git a/instances/tests/test_create_page_js.py b/instances/tests/test_create_page_js.py index c5544207..d15280ba 100644 --- a/instances/tests/test_create_page_js.py +++ b/instances/tests/test_create_page_js.py @@ -9,7 +9,7 @@ import unittest from unittest.mock import patch from django.conf import settings -from django.test import TestCase +from django.test import SimpleTestCase, TestCase from django.urls import reverse from instances.forms import NewVMForm from instances.tests.create_page import render_create_page @@ -183,7 +183,7 @@ console.log(JSON.stringify([field("#networks").value, field("#vm_mac").value])); self.assertEqual(NewVMForm.base_fields["mac"].clean(macs), macs) -class DiskSourceAndPresetScriptTests(TestCase): +class DiskSourceAndPresetScriptTests(SimpleTestCase): """The disk source choice enables only its own fields; a preset fills the sizes, picks a new disk and is announced.""" @@ -235,7 +235,7 @@ console.log(JSON.stringify({applied, cleared: pressed()}));""") self.assertEqual(out["cleared"], [["false", "text-body"], ["false", "text-body"]]) -class NewFormScriptTests(TestCase): +class NewFormScriptTests(SimpleTestCase): """A new form starts with one interface; the template's copy goes into the template's pool unless the user picks another.""" diff --git a/instances/tests/test_xss.py b/instances/tests/test_xss.py index a3061bb7..154f8594 100644 --- a/instances/tests/test_xss.py +++ b/instances/tests/test_xss.py @@ -8,7 +8,7 @@ from pathlib import Path from unittest.mock import patch from django.contrib.auth import get_user_model -from django.test import TestCase +from django.test import SimpleTestCase, TestCase from django.urls import reverse from accounts.models import UserInstance, UserSSHKey @@ -99,7 +99,7 @@ class JsonEndpointContentTypeTestCase(TestCase): self.assertJson(self.client.get(reverse("vm_logs", args=[self.instance.pk]))) -class TemplateHtmlConcatenationTestCase(TestCase): +class TemplateHtmlConcatenationTestCase(SimpleTestCase): """ The log table and the volume dropdown are filled by JavaScript from JSON that contains user-entered names. They must use DOM APIs (.text()/.val()) @@ -142,7 +142,7 @@ ALLOWED_HTML_SINKS = { } -class TemplateHtmlSinkInventoryTestCase(TestCase): +class TemplateHtmlSinkInventoryTestCase(SimpleTestCase): def test_every_html_sink_in_templates_is_reviewed(self): found = set() for path in ROOT.glob("*/templates/**/*.html"): diff --git a/operations/tests/test_kinds.py b/operations/tests/test_kinds.py index 94655f1e..5ef8a25b 100644 --- a/operations/tests/test_kinds.py +++ b/operations/tests/test_kinds.py @@ -2,7 +2,7 @@ from datetime import timedelta from types import SimpleNamespace from django.contrib.auth import get_user_model -from django.test import TestCase +from django.test import SimpleTestCase, TestCase from django.utils import timezone from operations import jobs @@ -11,7 +11,7 @@ from operations.models import TAKEOVER_AFTER, Claim, LeaseLost, Operation, Worke from operations.tests import fakes -class RegistryTestCase(TestCase): +class RegistryTestCase(SimpleTestCase): def test_kinds_register_by_name(self): self.assertIs(get_kind("test.noop"), KINDS["test.noop"]) self.assertEqual((label_of("test.noop"), label_of("unknown.kind")), ("No-op", "unknown.kind")) diff --git a/operations/tests/test_worker.py b/operations/tests/test_worker.py index 5947d4e7..582ee827 100644 --- a/operations/tests/test_worker.py +++ b/operations/tests/test_worker.py @@ -12,7 +12,7 @@ from unittest.mock import patch from django.conf import settings from django.contrib.auth import get_user_model from django.db import OperationalError, connection -from django.test import TransactionTestCase +from django.test import SimpleTestCase, TransactionTestCase from django.utils import timezone from appsettings.models import AppSettings @@ -345,14 +345,14 @@ class RequestJobTestCase(TransactionTestCase): self.assertEqual(fakes.EXPIRED, [str(other.pk)]) -class DataDirTestCase(TransactionTestCase): +class DataDirTestCase(SimpleTestCase): def test_the_data_dir_does_not_follow_the_log_file(self): with self.settings(WEBVIRTCLOUD_LOG_FILE="/var/log/wvc-test/webvirtcloud.log"): moved = data_dir() self.assertEqual(str(moved), str(settings.BASE_DIR / "data")) -class HostIdentityTestCase(TransactionTestCase): +class HostIdentityTestCase(SimpleTestCase): def setUp(self): directory = tempfile.TemporaryDirectory() self.addCleanup(directory.cleanup) diff --git a/webvirtcloud/tests/test_logging.py b/webvirtcloud/tests/test_logging.py index 153560a8..f9a9a51e 100644 --- a/webvirtcloud/tests/test_logging.py +++ b/webvirtcloud/tests/test_logging.py @@ -4,17 +4,18 @@ path, not the process working directory.""" import io import logging import os +import shutil from django.conf import settings from django.contrib.auth.models import User from django.http import HttpResponse -from django.test import RequestFactory, TestCase +from django.test import RequestFactory, SimpleTestCase, TestCase from webvirtcloud.log_context import RequestFilter from webvirtcloud.middleware import RequestIdMiddleware -class LoggingConfigTestCase(TestCase): +class LoggingConfigTestCase(SimpleTestCase): def test_default_handler_rotates(self): handler = settings.LOGGING["handlers"]["default"] self.assertEqual(handler["class"], "logging.handlers.RotatingFileHandler") @@ -33,6 +34,7 @@ class LoggingConfigTestCase(TestCase): import tempfile tmp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, tmp) log = os.path.join(tmp, "nested", "wvc.log") env = { **os.environ,