1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Fix tests and workaround issue with flake8

This commit is contained in:
grossmj 2021-10-18 22:12:10 +10:30
parent 01da25a7c7
commit 88d98cf02e
3 changed files with 9 additions and 11 deletions

View File

@ -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:

View File

@ -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')

View File

@ -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):