Replace global IntegerKeyValueSetting with per-view CatalogZone model
Track the catalog zone SOA serial per view instead of a single global value. The new CatalogZone model has a 1:1 FK to netbox_dns.models.View and its own soa_serial field; each view's catalog zone now increments independently. The existing global serial is preserved during migration by copying it into every view's new CatalogZone row. Change CatalogZoneMemberIdentifier.name from globally unique to unique per catalog zone (UniqueConstraint(name, catalog_zone)) and add a catalog_zone FK to enforce it. Remove the dns-settings management command, which was a generic interface over the now-removed IntegerKeyValueSetting model. Increment both catalog zone serials when a zone moves between views: the old view's catalog zone loses a member and the new view's gains one, so both must be bumped. Also refresh the member identifier's catalog_zone FK on a view move so it does not go stale. The pre_save handler now captures _old_view_id and the post_save handler detects view changes, increments the old view's serial inside on_commit (before the new view's), and re-creates the identifier. AI generated, code manually verified.
This commit is contained in:
1 parent
4ad110ca53
commit
9f5e40ae48
17 files changed
+429
-240
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Tests for management commands: dns-settings, dns-export-zone, dns-export-zones,
|
||||
"""Tests for management commands: dns-export-zone, dns-export-zones,
|
||||
dns-transfer-endpoint."""
|
||||
import os
|
||||
import tempfile
|
||||
@@ -9,60 +9,6 @@ import pytest
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
|
||||
from netbox_dns_bridge.models import IntegerKeyValueSetting
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestDnsSettingsCommand:
|
||||
def test_list_empty(self):
|
||||
IntegerKeyValueSetting.objects.all().delete()
|
||||
out = StringIO()
|
||||
call_command("dns-settings", "list", stdout=out)
|
||||
assert "No settings found" in out.getvalue()
|
||||
|
||||
def test_list_with_entries(self):
|
||||
IntegerKeyValueSetting.objects.create(key="k1", value=10)
|
||||
IntegerKeyValueSetting.objects.create(key="k2", value=20)
|
||||
out = StringIO()
|
||||
call_command("dns-settings", "list", stdout=out)
|
||||
output = out.getvalue()
|
||||
assert "k1: 10" in output
|
||||
assert "k2: 20" in output
|
||||
|
||||
def test_get_existing(self):
|
||||
IntegerKeyValueSetting.objects.create(key="serial", value=42)
|
||||
out = StringIO()
|
||||
call_command("dns-settings", "get", "serial", stdout=out)
|
||||
assert "serial: 42" in out.getvalue()
|
||||
|
||||
def test_get_missing_raises(self):
|
||||
with pytest.raises(CommandError, match="No setting"):
|
||||
call_command("dns-settings", "get", "nonexistent")
|
||||
|
||||
def test_get_without_key_raises(self):
|
||||
with pytest.raises(CommandError, match="key is required"):
|
||||
call_command("dns-settings", "get")
|
||||
|
||||
def test_set_existing(self):
|
||||
IntegerKeyValueSetting.objects.create(key="counter", value=5)
|
||||
out = StringIO()
|
||||
call_command("dns-settings", "set", "counter", 99, stdout=out)
|
||||
assert "Updated counter from 5 to 99" in out.getvalue()
|
||||
assert IntegerKeyValueSetting.objects.get(key="counter").value == 99
|
||||
|
||||
def test_set_missing_key_raises(self):
|
||||
with pytest.raises(CommandError, match="setting is required"):
|
||||
call_command("dns-settings", "set")
|
||||
|
||||
def test_set_without_value_raises(self):
|
||||
IntegerKeyValueSetting.objects.create(key="needval", value=1)
|
||||
with pytest.raises(CommandError, match="value is required"):
|
||||
call_command("dns-settings", "set", "needval")
|
||||
|
||||
def test_set_nonexistent_setting_raises(self):
|
||||
with pytest.raises(CommandError, match="No setting found"):
|
||||
call_command("dns-settings", "set", "ghost", 1)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestDnsExportZoneCommand:
|
||||
|
||||
Reference in new issue
Block a user