fix: handle NetBox device form clean result
This commit is contained in:
@@ -36,7 +36,7 @@ Release-Tag oder ein bestimmter Commit verwendet werden:
|
||||
|
||||
```bash
|
||||
/opt/netbox/venv/bin/pip install --upgrade --force-reinstall \
|
||||
"git+https://git.mrblake.cc/MrBlake/Netbox-Utilities.git@v0.8.4"
|
||||
"git+https://git.mrblake.cc/MrBlake/Netbox-Utilities.git@v0.8.5"
|
||||
```
|
||||
|
||||
Alternativ kann hinter dem `@` die vollständige Commit-ID stehen.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from netbox.plugins import PluginConfig, get_plugin_config
|
||||
|
||||
__version__ = "0.8.4"
|
||||
__version__ = "0.8.5"
|
||||
|
||||
|
||||
class NetBoxUtilitiesConfig(PluginConfig):
|
||||
|
||||
@@ -389,7 +389,8 @@ def _install_device_form():
|
||||
self.fields = reordered
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
super().clean()
|
||||
cleaned_data = self.cleaned_data
|
||||
try:
|
||||
width, horizontal_position = normalize_width_position(
|
||||
cleaned_data.get("utilities_rack_width"),
|
||||
|
||||
@@ -114,6 +114,31 @@ class RackWidthTest(SimpleTestCase):
|
||||
self.assertLess(html.index(width), html.index(horizontal_position))
|
||||
self.assertLess(html.index(horizontal_position), html.index(latitude))
|
||||
|
||||
def test_bound_device_form_clean_handles_netbox_clean_returning_none(self):
|
||||
from dcim.models import Device
|
||||
from netbox.registry import registry
|
||||
|
||||
edit_view = next(view["view"] for view in registry["views"]["dcim"]["device"] if view["name"] == "edit")
|
||||
object_type = SimpleNamespace(pk=1, model_class=lambda: Device)
|
||||
with (
|
||||
patch("core.models.ObjectType.objects.get_for_model", return_value=object_type),
|
||||
patch(
|
||||
"django.contrib.contenttypes.models.ContentType.objects.get_for_model",
|
||||
return_value=object_type,
|
||||
),
|
||||
patch("extras.models.CustomField.objects.get_for_model", return_value=[]),
|
||||
patch(
|
||||
"netbox_utilities.runtime._get_database_settings",
|
||||
return_value={"tenant_required": True},
|
||||
),
|
||||
):
|
||||
form = edit_view.form(data={})
|
||||
# NetBox 4.6.7's CheckLastUpdatedMixin.clean() updates
|
||||
# self.cleaned_data but deliberately returns None.
|
||||
with patch.object(form, "_post_clean"):
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertIsInstance(form.cleaned_data, dict)
|
||||
|
||||
@staticmethod
|
||||
def _anonymous_request():
|
||||
request = RequestFactory().get("/dcim/devices/1/edit/")
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "netbox-utilities"
|
||||
version = "0.8.4"
|
||||
version = "0.8.5"
|
||||
description = "Navigation, tenant utilities, partial-width rack devices, bulk uploads, and rack reordering for NetBox 4.6"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
Reference in New Issue
Block a user