From 66c477b99c69bec59e1859c4976c24a8094a22db Mon Sep 17 00:00:00 2001 From: afourmy Date: Fri, 19 Jul 2019 16:16:53 +0200 Subject: [PATCH] fix build lint / type hint / tests --- eNMS/controller/automation.py | 6 +++--- eNMS/controller/base.py | 2 +- eNMS/database/functions.py | 4 ++-- eNMS/services/data_validation/netmiko_prompts.py | 11 +---------- eNMS/services/data_validation/netmiko_validation.py | 11 +---------- eNMS/services/miscellaneous/rest_call.py | 2 +- eNMS/services/workflow/payload_validation.py | 2 +- eNMS/templates/forms/service_form.html | 7 ++++++- eNMS/templates/forms/workflow_form.html | 7 ++++++- 9 files changed, 22 insertions(+), 30 deletions(-) diff --git a/eNMS/controller/automation.py b/eNMS/controller/automation.py index 574a2511a..bc0ca06b8 100644 --- a/eNMS/controller/automation.py +++ b/eNMS/controller/automation.py @@ -7,7 +7,7 @@ from netmiko.ssh_dispatcher import CLASS_MAPPER, FILE_TRANSFER_MAP from pathlib import Path from re import search, sub -from typing import Any, Dict, List +from typing import Any, Dict, List, Optional from eNMS.concurrency import threaded_job from eNMS.controller.base import BaseController @@ -185,9 +185,9 @@ def calendar_init(self) -> dict: def scheduler_action(self, action: str) -> None: getattr(self.scheduler, action)() - def task_action(self, action: str, task_id: int) -> None: + def task_action(self, action: str, task_id: int) -> Optional[dict]: try: - getattr(fetch("Task", id=task_id), action)() + return getattr(fetch("Task", id=task_id), action)() except JobLookupError: return {"error": "This task no longer exists."} diff --git a/eNMS/controller/base.py b/eNMS/controller/base.py index 8268f74c0..5c863e590 100644 --- a/eNMS/controller/base.py +++ b/eNMS/controller/base.py @@ -377,7 +377,7 @@ def get_all(self, cls: str) -> List[dict]: def update(self, cls: str, **kwargs: Any) -> dict: try: - must_be_new = kwargs["id"] == "" + must_be_new = kwargs.get("id") == "" instance = factory(cls, must_be_new=must_be_new, **kwargs) Session.flush() return instance.serialized diff --git a/eNMS/database/functions.py b/eNMS/database/functions.py index eaef1ea19..5ef1c2640 100644 --- a/eNMS/database/functions.py +++ b/eNMS/database/functions.py @@ -64,14 +64,14 @@ def export(model: str) -> List[dict]: return [instance.to_dict(export=True) for instance in models[model].visible()] -def factory(cls_name: str, must_be_new=False, **kwargs: Any) -> Any: +def factory(cls_name: str, **kwargs: Any) -> Any: instance, instance_id = None, kwargs.pop("id", 0) if instance_id: instance = fetch(cls_name, id=instance_id) elif "name" in kwargs: instance = fetch(cls_name, allow_none=True, name=kwargs["name"]) if instance: - if must_be_new: + if kwargs.get("must_be_new"): raise Exception(f"There already is a {cls_name} with the same name.") else: instance.update(**kwargs) diff --git a/eNMS/services/data_validation/netmiko_prompts.py b/eNMS/services/data_validation/netmiko_prompts.py index 600c55943..d2785cf34 100644 --- a/eNMS/services/data_validation/netmiko_prompts.py +++ b/eNMS/services/data_validation/netmiko_prompts.py @@ -1,13 +1,4 @@ -from sqlalchemy import ( - Boolean, - Column, - Float, - ForeignKey, - Integer, - PickleType, - String, - Text, -) +from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, Text from sqlalchemy.ext.mutable import MutableDict from typing import Optional from wtforms import HiddenField diff --git a/eNMS/services/data_validation/netmiko_validation.py b/eNMS/services/data_validation/netmiko_validation.py index baf63f078..a53a80bfb 100644 --- a/eNMS/services/data_validation/netmiko_validation.py +++ b/eNMS/services/data_validation/netmiko_validation.py @@ -1,13 +1,4 @@ -from sqlalchemy import ( - Boolean, - Column, - Float, - ForeignKey, - Integer, - PickleType, - String, - Text, -) +from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, Text from sqlalchemy.ext.mutable import MutableDict from typing import Optional from wtforms import BooleanField, HiddenField diff --git a/eNMS/services/miscellaneous/rest_call.py b/eNMS/services/miscellaneous/rest_call.py index 2a5b64542..9e472d0f0 100644 --- a/eNMS/services/miscellaneous/rest_call.py +++ b/eNMS/services/miscellaneous/rest_call.py @@ -7,7 +7,7 @@ patch as rest_patch, ) from requests.auth import HTTPBasicAuth -from sqlalchemy import Boolean, Column, ForeignKey, Integer, PickleType, String, Text +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text from sqlalchemy.ext.mutable import MutableDict from sqlalchemy.types import JSON from typing import Optional diff --git a/eNMS/services/workflow/payload_validation.py b/eNMS/services/workflow/payload_validation.py index 2b524be78..182c280a7 100644 --- a/eNMS/services/workflow/payload_validation.py +++ b/eNMS/services/workflow/payload_validation.py @@ -1,4 +1,4 @@ -from sqlalchemy import Boolean, Column, ForeignKey, Integer, PickleType, String, Text +from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text from sqlalchemy.ext.mutable import MutableDict from typing import Optional from wtforms import HiddenField diff --git a/eNMS/templates/forms/service_form.html b/eNMS/templates/forms/service_form.html index bd66df8a1..1e86b8945 100644 --- a/eNMS/templates/forms/service_form.html +++ b/eNMS/templates/forms/service_form.html @@ -227,7 +227,12 @@ - +
{{ form.yaql_query(id=form_type + '-yaql_query', class="form-control add-id") }} diff --git a/eNMS/templates/forms/workflow_form.html b/eNMS/templates/forms/workflow_form.html index a7403499d..85d3807e0 100644 --- a/eNMS/templates/forms/workflow_form.html +++ b/eNMS/templates/forms/workflow_form.html @@ -219,7 +219,12 @@
- +
{{ form.yaql_query(id='workflow-yaql_query', class="form-control add-id") }}