Skip to content

Commit

Permalink
fix build lint / type hint / tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afourmy committed Jul 19, 2019
1 parent 4e12a74 commit 66c477b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 30 deletions.
6 changes: 3 additions & 3 deletions eNMS/controller/automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."}

Expand Down
2 changes: 1 addition & 1 deletion eNMS/controller/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions eNMS/database/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions eNMS/services/data_validation/netmiko_prompts.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 1 addition & 10 deletions eNMS/services/data_validation/netmiko_validation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion eNMS/services/miscellaneous/rest_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eNMS/services/workflow/payload_validation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion eNMS/templates/forms/service_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@
<label>Start New Connection</label>
</div>
</fieldset>
<label><label for="yaql_query">YaQL Query (populating will supersede service target in a parent workflow)</label></label>
<label
><label for="yaql_query"
>YaQL Query (populating will supersede service target in a parent
workflow)</label
></label
>
<div class="form-group">
{{ form.yaql_query(id=form_type + '-yaql_query', class="form-control
add-id") }}
Expand Down
7 changes: 6 additions & 1 deletion eNMS/templates/forms/workflow_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@
<label>Start New Connection</label>
</div>
</fieldset>
<label><label for="yaql_query">YaQL Query (populating will supersede service target in a parent workflow)</label></label>
<label
><label for="yaql_query"
>YaQL Query (populating will supersede service target in a parent
workflow)</label
></label
>
<div class="form-group">
{{ form.yaql_query(id='workflow-yaql_query', class="form-control
add-id") }}
Expand Down

0 comments on commit 66c477b

Please sign in to comment.