From 26091cfa8756237d5627845e0c493f002000f8cf Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 09:51:50 -0400 Subject: [PATCH 1/8] Suppress extraneous logging in BackgroundTaskTestCase --- netbox/core/tests/test_api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netbox/core/tests/test_api.py b/netbox/core/tests/test_api.py index d8fb8fd83d3..e9e77f2528c 100644 --- a/netbox/core/tests/test_api.py +++ b/netbox/core/tests/test_api.py @@ -9,6 +9,7 @@ from users.models import Token, User from utilities.testing import APITestCase, APIViewTestCases, TestCase +from utilities.testing.utils import disable_logging from ..models import * @@ -189,7 +190,8 @@ def test_background_task_requeue(self): # Enqueue & run a job that will fail job = queue.enqueue(self.dummy_job_failing) worker = get_worker('default') - worker.work(burst=True) + with disable_logging(): + worker.work(burst=True) self.assertTrue(job.is_failed) # Re-enqueue the failed job and check that its status has been reset @@ -231,7 +233,8 @@ def test_background_task_stop(self): self.assertEqual(job.get_status(), JobStatus.STARTED) response = self.client.post(reverse('core-api:rqtask-stop', args=[job.id]), **self.header) self.assertEqual(response.status_code, 200) - worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started + with disable_logging(): + worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection) self.assertEqual(len(started_job_registry), 0) From f166e8d8ce4ea18cc809d560f573be72f7974ad6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 09:56:54 -0400 Subject: [PATCH 2/8] Suppress extraneous logging in InterfaceTest --- netbox/dcim/tests/test_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index c3ac6053d70..8af539b047f 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -14,7 +14,7 @@ from netbox.api.serializers import GenericObjectSerializer from tenancy.models import Tenant from users.models import User -from utilities.testing import APITestCase, APIViewTestCases, create_test_device +from utilities.testing import APITestCase, APIViewTestCases, create_test_device, disable_logging from virtualization.models import Cluster, ClusterType from wireless.choices import WirelessChannelChoices from wireless.models import WirelessLAN @@ -1858,7 +1858,8 @@ def test_bulk_delete_child_interfaces(self): # Attempt to delete only the parent interface url = self._get_detail_url(interface1) - self.client.delete(url, **self.header) + with disable_logging(): + self.client.delete(url, **self.header) self.assertEqual(device.interfaces.count(), 4) # Parent was not deleted # Attempt to bulk delete parent & child together From 3d6e6bc2833454c1e0eb0aa09f767f1495802415 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 12:20:59 -0400 Subject: [PATCH 3/8] Suppress deprecation warnings in ScriptTest --- netbox/extras/tests/test_scripts.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/netbox/extras/tests/test_scripts.py b/netbox/extras/tests/test_scripts.py index bed8f0fc571..17eb5a31add 100644 --- a/netbox/extras/tests/test_scripts.py +++ b/netbox/extras/tests/test_scripts.py @@ -1,3 +1,4 @@ +import logging import tempfile from datetime import date, datetime, timezone @@ -7,6 +8,7 @@ from dcim.models import DeviceRole from extras.scripts import * +from utilities.testing import disable_logging CHOICES = ( ('ff0000', 'Red'), @@ -39,7 +41,8 @@ def test_load_yaml(self): datafile.write(bytes(YAML_DATA, 'UTF-8')) datafile.seek(0) - data = Script().load_yaml(datafile.name) + with disable_logging(level=logging.WARNING): + data = Script().load_yaml(datafile.name) self.assertEqual(data, { 'Foo': 123, 'Bar': 456, @@ -51,7 +54,8 @@ def test_load_json(self): datafile.write(bytes(JSON_DATA, 'UTF-8')) datafile.seek(0) - data = Script().load_json(datafile.name) + with disable_logging(level=logging.WARNING): + data = Script().load_json(datafile.name) self.assertEqual(data, { 'Foo': 123, 'Bar': 456, From 4db269635ae979d54e98d54ce1be378c00677c78 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 12:26:28 -0400 Subject: [PATCH 4/8] Fix warning suppression under VLANTest --- netbox/ipam/tests/test_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/tests/test_api.py b/netbox/ipam/tests/test_api.py index 4b9b340c44b..6255aaf867c 100644 --- a/netbox/ipam/tests/test_api.py +++ b/netbox/ipam/tests/test_api.py @@ -1,4 +1,5 @@ import json +import logging from django.urls import reverse from netaddr import IPNetwork @@ -9,7 +10,7 @@ from ipam.models import * from tenancy.models import Tenant from utilities.data import string_to_ranges -from utilities.testing import APITestCase, APIViewTestCases, create_test_device, disable_warnings +from utilities.testing import APITestCase, APIViewTestCases, create_test_device, disable_logging class AppTest(APITestCase): @@ -1026,7 +1027,7 @@ def test_delete_vlan_with_prefix(self): self.add_permissions('ipam.delete_vlan') url = reverse('ipam-api:vlan-detail', kwargs={'pk': vlan.pk}) - with disable_warnings('netbox.api.views.ModelViewSet'): + with disable_logging(level=logging.WARNING): response = self.client.delete(url, **self.header) self.assertHttpStatus(response, status.HTTP_409_CONFLICT) From 3f3d379a1c184d2d072b2438250d392bdc2e57a8 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 12:30:23 -0400 Subject: [PATCH 5/8] Suppress warning under VMInterfaceTest --- netbox/virtualization/tests/test_api.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/netbox/virtualization/tests/test_api.py b/netbox/virtualization/tests/test_api.py index dfa8309a053..e07f4dc06d2 100644 --- a/netbox/virtualization/tests/test_api.py +++ b/netbox/virtualization/tests/test_api.py @@ -1,3 +1,5 @@ +import logging + from django.test import tag from django.urls import reverse from netaddr import IPNetwork @@ -10,7 +12,9 @@ from extras.models import ConfigTemplate, CustomField from ipam.choices import VLANQinQRoleChoices from ipam.models import Prefix, VLAN, VRF -from utilities.testing import APITestCase, APIViewTestCases, create_test_device, create_test_virtualmachine +from utilities.testing import ( + APITestCase, APIViewTestCases, create_test_device, create_test_virtualmachine, disable_logging, +) from virtualization.choices import * from virtualization.models import * @@ -402,7 +406,8 @@ def test_bulk_delete_child_interfaces(self): # Attempt to delete only the parent interface url = self._get_detail_url(interface1) - self.client.delete(url, **self.header) + with disable_logging(level=logging.WARNING): + self.client.delete(url, **self.header) self.assertEqual(virtual_machine.interfaces.count(), 4) # Parent was not deleted # Attempt to bulk delete parent & child together From b8c0c0faeba3a3d7e9d28e10d573709e50815e81 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 12:47:05 -0400 Subject: [PATCH 6/8] Suppress extraneous logging in BackgroundTaskTestCase --- netbox/core/tests/test_views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/netbox/core/tests/test_views.py b/netbox/core/tests/test_views.py index 047b51ef64a..96a4292df9d 100644 --- a/netbox/core/tests/test_views.py +++ b/netbox/core/tests/test_views.py @@ -14,7 +14,7 @@ from core.models import * from dcim.models import Site from users.models import User -from utilities.testing import TestCase, ViewTestCases, create_tags +from utilities.testing import TestCase, ViewTestCases, create_tags, disable_logging class DataSourceTestCase(ViewTestCases.PrimaryObjectViewTestCase): @@ -271,7 +271,8 @@ def test_background_task_requeue(self): # Enqueue & run a job that will fail job = queue.enqueue(self.dummy_job_failing) worker = get_worker('default') - worker.work(burst=True) + with disable_logging(): + worker.work(burst=True) self.assertTrue(job.is_failed) # Re-enqueue the failed job and check that its status has been reset @@ -317,7 +318,8 @@ def test_background_task_stop(self): self.assertEqual(len(started_job_registry), 1) response = self.client.get(reverse('core:background_task_stop', args=[job.id])) self.assertEqual(response.status_code, 302) - worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started + with disable_logging(): + worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started self.assertEqual(len(started_job_registry), 0) canceled_job_registry = FailedJobRegistry(queue.name, connection=queue.connection) From dcdb0b8846aa400b57c51c14418fe24010bacea5 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 13:27:01 -0400 Subject: [PATCH 7/8] Suppress warnings from drf_spectacular when testing schema API view --- netbox/utilities/tests/test_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/tests/test_api.py b/netbox/utilities/tests/test_api.py index 2c3ba0566fc..b6e5e136046 100644 --- a/netbox/utilities/tests/test_api.py +++ b/netbox/utilities/tests/test_api.py @@ -1,5 +1,6 @@ from django.test import Client, TestCase, override_settings from django.urls import reverse +from drf_spectacular.drainage import GENERATOR_STATS from rest_framework import status from core.models import ObjectType @@ -264,5 +265,6 @@ def test_api_docs(self): self.assertEqual(response.status_code, 200) url = reverse('schema') - response = self.client.get(url) + with GENERATOR_STATS.silence(): # Suppress schema generator warnings + response = self.client.get(url) self.assertEqual(response.status_code, 200) From 01a09be2a35bb24f1dd27cffd2e9368ed7195b7c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 16 May 2025 13:50:40 -0400 Subject: [PATCH 8/8] Add bulk edit data to subscription & notification tests --- netbox/extras/tests/test_api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 6e3fb37fc04..29af3f96d1f 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -2,7 +2,7 @@ from django.contrib.contenttypes.models import ContentType from django.urls import reverse -from django.utils.timezone import make_aware +from django.utils.timezone import make_aware, now from rest_framework import status from core.choices import ManagedFileRootPathChoices @@ -991,6 +991,10 @@ def setUpTestData(cls): }, ] + cls.bulk_update_data = { + 'user': users[3].pk, + } + class NotificationGroupTest(APIViewTestCases.APIViewTestCase): model = NotificationGroup @@ -1072,6 +1076,9 @@ def setUpTestData(cls): class NotificationTest(APIViewTestCases.APIViewTestCase): model = Notification brief_fields = ['display', 'event_type', 'id', 'object_id', 'object_type', 'read', 'url', 'user'] + bulk_update_data = { + 'read': now(), + } @classmethod def setUpTestData(cls):