import pytest from netbox_services.engine.allocators import FirstFreeIPAddressAllocator, SpecificAllocator @pytest.mark.django_db class TestFirstFreeIPAddressAllocator: def test_allocate_creates_ip(self, db): from ipam.models import IPAddress, Prefix from netbox_services.engine.context import Context Prefix.objects.create(prefix="10.99.0.0/24") allocator = FirstFreeIPAddressAllocator({ "strategy": "first_free", "prefix": {"type": "prefix", "filters": {}}, }) ip = allocator.allocate(Context(service=None)) assert ip is not None assert "10.99.0." in str(ip.address) def test_no_prefix_raises(self, db): from netbox_services.engine.context import Context allocator = FirstFreeIPAddressAllocator({ "strategy": "first_free", "prefix": {"type": "prefix", "filters": {"description": "no-such-prefix"}}, }) with pytest.raises(ValueError): allocator.allocate(Context(service=None)) @pytest.mark.django_db class TestSpecificAllocator: def test_specific_address(self, db): from netbox_services.engine.context import Context allocator = SpecificAllocator({"strategy": "specific", "address": "10.50.0.1/24"}) ip = allocator.allocate(Context(service=None)) assert str(ip.address) == "10.50.0.1/24" def test_specific_requires_address_or_path(self, db): from netbox_services.engine.context import Context allocator = SpecificAllocator({"strategy": "specific"}) with pytest.raises(ValueError): allocator.allocate(Context(service=None))