style: ruff format and the lint rules of the driver standard
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM driver uses (E, F, I, UP, B at line length 100, Python 3.10). Mapping and Iterable come from collections.abc, imports are sorted. What ruff cannot fix comes in the next commit.
This commit is contained in:
1 parent
5b24675a12
commit
09029ca0a4
29 files changed
+985
-456
No files matched your search
+29
-10
@@ -17,7 +17,7 @@ def fixture_file(mockup: str, path: str) -> Path:
|
||||
path = path.split("#", 1)[0].split("?", 1)[0].rstrip("/")
|
||||
if not path.startswith(PREFIX):
|
||||
raise ValueError(f"not a Redfish path: {path}")
|
||||
relative = path[len(PREFIX):].lstrip("/")
|
||||
relative = path[len(PREFIX) :].lstrip("/")
|
||||
return FIXTURES / mockup / relative / "index.json"
|
||||
|
||||
|
||||
@@ -64,8 +64,14 @@ class MockupServer:
|
||||
for method in (responses.GET, responses.POST, responses.DELETE):
|
||||
rsps.add_callback(method, anything, callback=self._handle)
|
||||
|
||||
def override(self, method: str, path: str, status: int, body: dict | str | None = None,
|
||||
headers: dict | None = None):
|
||||
def override(
|
||||
self,
|
||||
method: str,
|
||||
path: str,
|
||||
status: int,
|
||||
body: dict | str | None = None,
|
||||
headers: dict | None = None,
|
||||
):
|
||||
self.overrides[(method, path)] = (status, body if body is not None else {}, headers or {})
|
||||
|
||||
@staticmethod
|
||||
@@ -82,8 +88,11 @@ class MockupServer:
|
||||
if key in self.overrides:
|
||||
return self._reply(*self.overrides[key])
|
||||
if request.method == "POST" and parts.path == SESSIONS:
|
||||
return self._reply(201, {"@odata.id": SESSION_PATH, "Id": "0123456789abcdef"},
|
||||
{"X-Auth-Token": TOKEN, "Location": BASE_URL + SESSION_PATH})
|
||||
return self._reply(
|
||||
201,
|
||||
{"@odata.id": SESSION_PATH, "Id": "0123456789abcdef"},
|
||||
{"X-Auth-Token": TOKEN, "Location": BASE_URL + SESSION_PATH},
|
||||
)
|
||||
if request.method == "DELETE" and parts.path == SESSION_PATH:
|
||||
return self._reply(204, {})
|
||||
if request.method == "GET":
|
||||
@@ -91,13 +100,23 @@ class MockupServer:
|
||||
return self._reply(200, load(self.mockup, parts.path))
|
||||
except (FileNotFoundError, ValueError):
|
||||
pass
|
||||
return self._reply(404, {"error": {"code": "Base.1.0.ResourceMissingAtURI",
|
||||
"message": f"{parts.path} not found"}})
|
||||
return self._reply(
|
||||
404,
|
||||
{
|
||||
"error": {
|
||||
"code": "Base.1.0.ResourceMissingAtURI",
|
||||
"message": f"{parts.path} not found",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
def calls(self, method: str | None = None, path: str | None = None):
|
||||
return [c for c in self.rsps.calls
|
||||
if (method is None or c.request.method == method)
|
||||
and (path is None or urlsplit(c.request.url).path == path)]
|
||||
return [
|
||||
c
|
||||
for c in self.rsps.calls
|
||||
if (method is None or c.request.method == method)
|
||||
and (path is None or urlsplit(c.request.url).path == path)
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in new issue
Block a user