Upgrade models to full NetboxModel to allow UI/API interaction:
modified: netbox_dns_bridge/models.py deleted: netbox_dns_bridge/migrations/0003_catalogzone_and_per_zone_identifier.py new file: netbox_dns_bridge/migrations/0003_full_netbox_models.py Adjust model access and function calls to match new models: modified: netbox_dns_bridge/signals/netbox_dns_zones.py modified: netbox_dns_bridge/management/commands/dns_transfer_endpoint/catalog_zone_manager.py modified: netbox_dns_bridge/management/commands/dns_transfer_endpoint/request_handler.py Update UI elements and permission interactions: modified: netbox_dns_bridge/filtersets.py modified: netbox_dns_bridge/forms.py modified: netbox_dns_bridge/jobs/notify.py modified: netbox_dns_bridge/navigation.py modified: netbox_dns_bridge/tables.py deleted: netbox_dns_bridge/templates/netbox_dns_bridge/catalog_zone_members.html new file: netbox_dns_bridge/templates/netbox_dns_bridge/catalogzone.html new file: netbox_dns_bridge/templates/netbox_dns_bridge/catalogzonemember.html deleted: netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html new file: netbox_dns_bridge/templates/netbox_dns_bridge/seentransferclient.html modified: netbox_dns_bridge/urls.py modified: netbox_dns_bridge/views.py AI/LLM updated tests (Not verified): modified: netbox_dns_bridge/tests/conftest.py modified: netbox_dns_bridge/tests/test_catalog_zone_manager.py modified: netbox_dns_bridge/tests/test_models.py modified: netbox_dns_bridge/tests/test_notify.py modified: netbox_dns_bridge/tests/test_request_handler_integration.py modified: netbox_dns_bridge/tests/test_signals.py modified: netbox_dns_bridge/tests/test_smoke.py modified: netbox_dns_bridge/tests/test_views.py
This commit is contained in:
1 parent
14805ed32b
commit
1c51206196
26 files changed
+813
-451
No files matched your search
@@ -1,4 +1,4 @@
|
||||
"""Tests for views: CatalogZoneMembersView, CatalogZoneListView, CatalogZoneEditView, NotifyOverviewView — auth gate and context."""
|
||||
"""Tests for views: CatalogZone list/detail/edit, CatalogZoneMember list/detail, SeenTransferClient list/detail — auth gate and context."""
|
||||
import pytest
|
||||
from django.test import Client
|
||||
from django.contrib.auth import get_user_model
|
||||
@@ -28,7 +28,7 @@ def regular_user(db):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestCatalogZoneMembersView:
|
||||
class TestCatalogZoneMemberListView:
|
||||
def test_unauthenticated_redirects_to_login(self, client):
|
||||
resp = client.get("/plugins/dns-bridge/catalog-zone-members/")
|
||||
assert resp.status_code in (302, 403)
|
||||
@@ -38,11 +38,48 @@ class TestCatalogZoneMembersView:
|
||||
resp = client.get("/plugins/dns-bridge/catalog-zone-members/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_superuser_can_access(self, client, superuser):
|
||||
def test_superuser_can_access(self, client, superuser, make_zone):
|
||||
make_zone(name="member-list.test")
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/catalog-zone-members/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_list_contains_members(self, client, superuser, make_zone):
|
||||
zone = make_zone(name="member-row.test")
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/catalog-zone-members/")
|
||||
member_list = list(resp.context["table"].data)
|
||||
assert len(member_list) >= 1
|
||||
m = next(m for m in member_list if m.zone_id == zone.id)
|
||||
assert m.name
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestCatalogZoneMemberDetailView:
|
||||
def test_unauthenticated_redirects_to_login(self, client, make_zone):
|
||||
zone = make_zone(name="member-detail.test")
|
||||
from netbox_dns_bridge.models import CatalogZoneMember
|
||||
m = CatalogZoneMember.objects.get(zone=zone)
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zone-members/{m.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_regular_user_forbidden(self, client, regular_user, make_zone):
|
||||
zone = make_zone(name="member-detail-forbidden.test")
|
||||
from netbox_dns_bridge.models import CatalogZoneMember
|
||||
m = CatalogZoneMember.objects.get(zone=zone)
|
||||
client.login(username="regular", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zone-members/{m.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_superuser_can_access_detail(self, client, superuser, make_zone):
|
||||
zone = make_zone(name="member-detail-get.test")
|
||||
from netbox_dns_bridge.models import CatalogZoneMember
|
||||
m = CatalogZoneMember.objects.get(zone=zone)
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zone-members/{m.pk}/")
|
||||
assert resp.status_code == 200
|
||||
assert resp.context["object"].name == m.name
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestCatalogZoneListView:
|
||||
@@ -138,45 +175,104 @@ class TestCatalogZoneEditView:
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestNotifyOverviewView:
|
||||
class TestCatalogZoneDetailView:
|
||||
def test_unauthenticated_redirects_to_login(self, client, make_view):
|
||||
view = make_view(name="detail-cz-view")
|
||||
from netbox_dns_bridge.models import CatalogZone
|
||||
cz = CatalogZone.objects.create(view=view)
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zones/{cz.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_regular_user_forbidden(self, client, regular_user, make_view):
|
||||
view = make_view(name="detail-cz-view-forbidden")
|
||||
from netbox_dns_bridge.models import CatalogZone
|
||||
cz = CatalogZone.objects.create(view=view)
|
||||
client.login(username="regular", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zones/{cz.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_superuser_can_access_detail(self, client, superuser, make_view):
|
||||
view = make_view(name="detail-cz-view-get")
|
||||
from netbox_dns_bridge.models import CatalogZone
|
||||
cz = CatalogZone.objects.create(view=view, soa_serial=42)
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/catalog-zones/{cz.pk}/")
|
||||
assert resp.status_code == 200
|
||||
assert resp.context["object"].soa_serial == 42
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSeenTransferClientListView:
|
||||
def test_unauthenticated_redirects_to_login(self, client):
|
||||
resp = client.get("/plugins/dns-bridge/notify/")
|
||||
resp = client.get("/plugins/dns-bridge/seen-transfer-clients/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_regular_user_forbidden(self, client, regular_user):
|
||||
client.login(username="regular", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/notify/")
|
||||
resp = client.get("/plugins/dns-bridge/seen-transfer-clients/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_superuser_can_access(self, client, superuser):
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/notify/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_context_contains_seen_clients(self, client, superuser, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClients
|
||||
def test_superuser_can_access(self, client, superuser, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClient
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="notify-view")
|
||||
SeenTransferClients.objects.create(
|
||||
view = make_view(name="stc-list-view")
|
||||
SeenTransferClient.objects.create(
|
||||
source_ip="192.0.2.1", view=view, last_seen=timezone.now()
|
||||
)
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/notify/")
|
||||
assert "seen_clients" in resp.context
|
||||
clients = list(resp.context["seen_clients"])
|
||||
assert len(clients) == 1
|
||||
assert clients[0].source_ip == "192.0.2.1"
|
||||
resp = client.get("/plugins/dns-bridge/seen-transfer-clients/")
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_seen_clients_ordered_by_ip(self, client, superuser, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClients
|
||||
def test_list_contains_clients(self, client, superuser, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClient
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="ord-notify-view")
|
||||
now = timezone.now()
|
||||
for ip in ["10.0.0.3", "10.0.0.1", "10.0.0.2"]:
|
||||
SeenTransferClients.objects.create(source_ip=ip, view=view, last_seen=now)
|
||||
view = make_view(name="stc-list-row-view")
|
||||
SeenTransferClient.objects.create(
|
||||
source_ip="192.0.2.1", view=view, last_seen=timezone.now()
|
||||
)
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get("/plugins/dns-bridge/notify/")
|
||||
ips = [c.source_ip for c in resp.context["seen_clients"]]
|
||||
assert ips == ["10.0.0.1", "10.0.0.2", "10.0.0.3"]
|
||||
resp = client.get("/plugins/dns-bridge/seen-transfer-clients/")
|
||||
client_list = list(resp.context["table"].data)
|
||||
assert len(client_list) >= 1
|
||||
assert client_list[0].source_ip == "192.0.2.1"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSeenTransferClientDetailView:
|
||||
def test_unauthenticated_redirects_to_login(self, client, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClient
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="stc-detail-view")
|
||||
c = SeenTransferClient.objects.create(
|
||||
source_ip="192.0.2.1", view=view, last_seen=timezone.now()
|
||||
)
|
||||
resp = client.get(f"/plugins/dns-bridge/seen-transfer-clients/{c.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_regular_user_forbidden(self, client, regular_user, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClient
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="stc-detail-forbidden-view")
|
||||
c = SeenTransferClient.objects.create(
|
||||
source_ip="192.0.2.1", view=view, last_seen=timezone.now()
|
||||
)
|
||||
client.login(username="regular", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/seen-transfer-clients/{c.pk}/")
|
||||
assert resp.status_code in (302, 403)
|
||||
|
||||
def test_superuser_can_access_detail(self, client, superuser, make_view):
|
||||
from netbox_dns_bridge.models import SeenTransferClient
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="stc-detail-get-view")
|
||||
c = SeenTransferClient.objects.create(
|
||||
source_ip="192.0.2.42", view=view, last_seen=timezone.now()
|
||||
)
|
||||
client.login(username="admin", password="testpass")
|
||||
resp = client.get(f"/plugins/dns-bridge/seen-transfer-clients/{c.pk}/")
|
||||
assert resp.status_code == 200
|
||||
assert resp.context["object"].source_ip == "192.0.2.42"
|
||||
Reference in new issue
Block a user