From 88d98cf02eda5adb5ccd9c3a8b9090fc4cb0d10d Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 18 Oct 2021 22:12:10 +1030 Subject: [PATCH] Fix tests and workaround issue with flake8 --- gns3server/controller/appliance_manager.py | 11 +++++------ gns3server/schemas/controller/appliances.py | 4 ++-- tests/controller/test_controller.py | 5 ++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gns3server/controller/appliance_manager.py b/gns3server/controller/appliance_manager.py index c00b26fd..eb968f0d 100644 --- a/gns3server/controller/appliance_manager.py +++ b/gns3server/controller/appliance_manager.py @@ -298,19 +298,18 @@ class ApplianceManager: path = os.path.join(directory, file) try: with open(path, encoding="utf-8") as f: - json_data = json.load(f) - schemas.Appliance.parse_obj(json_data) - appliance = Appliance(path, json_data, builtin=builtin) - appliance_data = appliance.asdict() # Check if loaded without error + appliance = Appliance(path, json.load(f), builtin=builtin) + json_data = appliance.asdict() # Check if loaded without error if appliance.status != "broken": + schemas.Appliance.parse_obj(json_data) self._appliances[appliance.id] = appliance if not appliance.symbol or appliance.symbol.startswith(":/symbols/"): # apply a default symbol if the appliance has none or a default symbol - default_symbol = self._get_default_symbol(appliance_data, symbol_theme) + default_symbol = self._get_default_symbol(json_data, symbol_theme) if default_symbol: appliance.symbol = default_symbol except (ValueError, OSError, KeyError, ValidationError) as e: - log.warning(f"Cannot load appliance file '{path}': {e}") + print(f"Cannot load appliance file '{path}': {e}") continue def _get_default_symbol(self, appliance: dict, symbol_theme: str) -> str: diff --git a/gns3server/schemas/controller/appliances.py b/gns3server/schemas/controller/appliances.py index ceb96459..e6534736 100644 --- a/gns3server/schemas/controller/appliances.py +++ b/gns3server/schemas/controller/appliances.py @@ -323,7 +323,7 @@ class Image(BaseModel): filename: str = Field(..., title='Filename') version: str = Field(..., title='Version of the file') - md5sum: constr(regex=r'^[a-f0-9]{32}$') = Field(..., title='md5sum of the file') + md5sum: str = Field(..., title='md5sum of the file', regex='^[a-f0-9]{32}$') filesize: int = Field(..., title='File size in bytes') download_url: Optional[Union[AnyUrl, constr(max_length=0)]] = Field( None, title='Download url where you can download the appliance from a browser' @@ -353,7 +353,7 @@ class Images(BaseModel): class Version(BaseModel): name: str = Field(..., title='Name of the version') - idlepc: Optional[constr(regex=r'^0x[0-9a-f]{8}')] = None + idlepc: Optional[str] = Field(None, regex='^0x[0-9a-f]{8}') images: Optional[Images] = Field(None, title='Images used for this version') diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py index 4b26b054..9f2060e9 100644 --- a/tests/controller/test_controller.py +++ b/tests/controller/test_controller.py @@ -385,14 +385,13 @@ def test_appliances(controller, config, tmpdir): for appliance in controller.appliance_manager.appliances.values(): assert appliance.asdict()["status"] != "broken" assert "Alpine Linux" in [c.asdict()["name"] for c in controller.appliance_manager.appliances.values()] - assert "My Appliance" in [c.asdict()["name"] for c in controller.appliance_manager.appliances.values()] + assert "My Appliance" not in [c.asdict()["name"] for c in controller.appliance_manager.appliances.values()] for c in controller.appliance_manager.appliances.values(): j = c.asdict() if j["name"] == "Alpine Linux": assert j["builtin"] - elif j["name"] == "My Appliance": - assert not j["builtin"] + @pytest.mark.asyncio async def test_autoidlepc(controller):