mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
test: classes that use no database are SimpleTestCase
Ten classes ran on TestCase or TransactionTestCase although they read files, templates or scripts only. SimpleTestCase skips the transaction and refuses a database query, so a test that starts to use the database says so. LoggingConfigTestCase also removes the temporary directory it makes.
This commit is contained in:
parent
ee6b8d3e10
commit
03811cc4ab
6 changed files with 17 additions and 15 deletions
|
|
@ -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"), [])
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
||||
|
|
|
|||
|
|
@ -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"):
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue