mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
Fix tests and workaround issue with flake8
This commit is contained in:
parent
01da25a7c7
commit
88d98cf02e
@ -298,19 +298,18 @@ class ApplianceManager:
|
|||||||
path = os.path.join(directory, file)
|
path = os.path.join(directory, file)
|
||||||
try:
|
try:
|
||||||
with open(path, encoding="utf-8") as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
json_data = json.load(f)
|
appliance = Appliance(path, json.load(f), builtin=builtin)
|
||||||
schemas.Appliance.parse_obj(json_data)
|
json_data = appliance.asdict() # Check if loaded without error
|
||||||
appliance = Appliance(path, json_data, builtin=builtin)
|
|
||||||
appliance_data = appliance.asdict() # Check if loaded without error
|
|
||||||
if appliance.status != "broken":
|
if appliance.status != "broken":
|
||||||
|
schemas.Appliance.parse_obj(json_data)
|
||||||
self._appliances[appliance.id] = appliance
|
self._appliances[appliance.id] = appliance
|
||||||
if not appliance.symbol or appliance.symbol.startswith(":/symbols/"):
|
if not appliance.symbol or appliance.symbol.startswith(":/symbols/"):
|
||||||
# apply a default symbol if the appliance has none or a default symbol
|
# 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:
|
if default_symbol:
|
||||||
appliance.symbol = default_symbol
|
appliance.symbol = default_symbol
|
||||||
except (ValueError, OSError, KeyError, ValidationError) as e:
|
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
|
continue
|
||||||
|
|
||||||
def _get_default_symbol(self, appliance: dict, symbol_theme: str) -> str:
|
def _get_default_symbol(self, appliance: dict, symbol_theme: str) -> str:
|
||||||
|
@ -323,7 +323,7 @@ class Image(BaseModel):
|
|||||||
|
|
||||||
filename: str = Field(..., title='Filename')
|
filename: str = Field(..., title='Filename')
|
||||||
version: str = Field(..., title='Version of the file')
|
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')
|
filesize: int = Field(..., title='File size in bytes')
|
||||||
download_url: Optional[Union[AnyUrl, constr(max_length=0)]] = Field(
|
download_url: Optional[Union[AnyUrl, constr(max_length=0)]] = Field(
|
||||||
None, title='Download url where you can download the appliance from a browser'
|
None, title='Download url where you can download the appliance from a browser'
|
||||||
@ -353,7 +353,7 @@ class Images(BaseModel):
|
|||||||
class Version(BaseModel):
|
class Version(BaseModel):
|
||||||
|
|
||||||
name: str = Field(..., title='Name of the version')
|
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')
|
images: Optional[Images] = Field(None, title='Images used for this version')
|
||||||
|
|
||||||
|
|
||||||
|
@ -385,14 +385,13 @@ def test_appliances(controller, config, tmpdir):
|
|||||||
for appliance in controller.appliance_manager.appliances.values():
|
for appliance in controller.appliance_manager.appliances.values():
|
||||||
assert appliance.asdict()["status"] != "broken"
|
assert appliance.asdict()["status"] != "broken"
|
||||||
assert "Alpine Linux" in [c.asdict()["name"] for c in controller.appliance_manager.appliances.values()]
|
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():
|
for c in controller.appliance_manager.appliances.values():
|
||||||
j = c.asdict()
|
j = c.asdict()
|
||||||
if j["name"] == "Alpine Linux":
|
if j["name"] == "Alpine Linux":
|
||||||
assert j["builtin"]
|
assert j["builtin"]
|
||||||
elif j["name"] == "My Appliance":
|
|
||||||
assert not j["builtin"]
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_autoidlepc(controller):
|
async def test_autoidlepc(controller):
|
||||||
|
Loading…
Reference in New Issue
Block a user