Merge branch '3.1' into fix/duplicate-device-configs-merge

This commit is contained in:
Jeremy Grossmann authored and GitHub committed 2026-10-06 16:10:23 +02:00
commit 0170d2c8ce
34 files changed
+276 -70

No files matched your search

@@ -117,6 +117,28 @@ class TestControllerProjectRoutes:
assert response.status_code == status.HTTP_200_OK
assert response.json()["name"] == "test2"
async def test_update_project_ignores_path_and_project_id(
self, app: FastAPI, client: AsyncClient, controller: Controller
) -> None:
params = {"name": "test", "project_id": "10010203-0405-0607-0809-0a0b0c0d0e0f"}
response = await client.post(app.url_path_for("create_project"), json=params)
assert response.status_code == status.HTTP_201_CREATED
path = response.json()["path"]
params = {
"name": "test2",
"path": os.path.join(os.path.dirname(path), "other"),
"project_id": "20010203-0405-0607-0809-0a0b0c0d0e0f",
}
response = await client.put(
app.url_path_for("update_project", project_id="10010203-0405-0607-0809-0a0b0c0d0e0f"), json=params
)
assert response.status_code == status.HTTP_200_OK
assert response.json()["name"] == "test2"
assert response.json()["path"] == path
assert response.json()["project_id"] == "10010203-0405-0607-0809-0a0b0c0d0e0f"
async def test_update_project_with_variables(
self, app: FastAPI, client: AsyncClient, controller: Controller
) -> None:
+44
View File
@@ -0,0 +1,44 @@
import importlib
import inspect
import pkgutil
import pytest
from pydantic import BaseModel
from gns3server import schemas
from gns3server.schemas.update import PartialUpdateModel
def _discover_update_models():
models = {}
for module_info in pkgutil.walk_packages(schemas.__path__, f"{schemas.__name__}."):
module = importlib.import_module(module_info.name)
for name, cls in vars(module).items():
if inspect.isclass(cls) and issubclass(cls, BaseModel) and name.endswith("Update"):
models[f"{cls.__module__}.{cls.__qualname__}"] = cls
return models
UPDATE_MODELS = _discover_update_models()
PARTIAL_UPDATE_MODELS = {k: v for k, v in UPDATE_MODELS.items() if issubclass(v, PartialUpdateModel)}
@pytest.mark.parametrize("model", UPDATE_MODELS.values(), ids=UPDATE_MODELS.keys())
def test_update_schema_publishes_no_defaults(model):
properties = model.model_json_schema()["properties"]
assert {name: p["default"] for name, p in properties.items() if p.get("default") is not None} == {}
@pytest.mark.parametrize("model", PARTIAL_UPDATE_MODELS.values(), ids=PARTIAL_UPDATE_MODELS.keys())
def test_partial_update_schema_drops_excluded_fields(model):
inherited = {field for base in model.__mro__[1:] if hasattr(base, "model_fields") for field in base.model_fields}
for field in model.update_excluded_fields:
assert field in inherited
assert field not in model.model_fields
assert model.model_validate({field: None}).model_dump(exclude_unset=True) == {}
@pytest.mark.parametrize("model", PARTIAL_UPDATE_MODELS.values(), ids=PARTIAL_UPDATE_MODELS.keys())
def test_partial_update_schema_requires_nothing(model):
assert model().model_dump() == {}
assert model().model_dump_json() == "{}"