Merging upstream version 1.3.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5b922100c9
commit
8a6a3342fc
337 changed files with 16571 additions and 4891 deletions
|
@ -1,11 +1,11 @@
|
|||
# Copyright (c) 2023-2024 Arista Networks, Inc.
|
||||
# Copyright (c) 2023-2025 Arista Networks, Inc.
|
||||
# Use of this source code is governed by the Apache License 2.0
|
||||
# that can be found in the LICENSE file.
|
||||
"""Unit tests the asynceapi.device module."""
|
||||
"""Unit tests for the asynceapi.device module."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import pytest
|
||||
from httpx import HTTPStatusError
|
||||
|
@ -17,6 +17,8 @@ from .test_data import ERROR_EAPI_RESPONSE, JSONRPC_REQUEST_TEMPLATE, SUCCESS_EA
|
|||
if TYPE_CHECKING:
|
||||
from pytest_httpx import HTTPXMock
|
||||
|
||||
from asynceapi._types import EapiComplexCommand, EapiSimpleCommand
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cmds",
|
||||
|
@ -30,10 +32,10 @@ if TYPE_CHECKING:
|
|||
async def test_jsonrpc_exec_success(
|
||||
asynceapi_device: Device,
|
||||
httpx_mock: HTTPXMock,
|
||||
cmds: list[str | dict[str, Any]],
|
||||
cmds: list[EapiSimpleCommand | EapiComplexCommand],
|
||||
) -> None:
|
||||
"""Test the Device.jsonrpc_exec method with a successful response. Simple and complex commands are tested."""
|
||||
jsonrpc_request: dict[str, Any] = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request["params"]["cmds"] = cmds
|
||||
|
||||
httpx_mock.add_response(json=SUCCESS_EAPI_RESPONSE)
|
||||
|
@ -55,19 +57,18 @@ async def test_jsonrpc_exec_success(
|
|||
async def test_jsonrpc_exec_eapi_command_error(
|
||||
asynceapi_device: Device,
|
||||
httpx_mock: HTTPXMock,
|
||||
cmds: list[str | dict[str, Any]],
|
||||
cmds: list[EapiSimpleCommand | EapiComplexCommand],
|
||||
) -> None:
|
||||
"""Test the Device.jsonrpc_exec method with an error response. Simple and complex commands are tested."""
|
||||
jsonrpc_request: dict[str, Any] = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request["params"]["cmds"] = cmds
|
||||
|
||||
error_eapi_response: dict[str, Any] = ERROR_EAPI_RESPONSE.copy()
|
||||
httpx_mock.add_response(json=error_eapi_response)
|
||||
httpx_mock.add_response(json=ERROR_EAPI_RESPONSE)
|
||||
|
||||
with pytest.raises(EapiCommandError) as exc_info:
|
||||
await asynceapi_device.jsonrpc_exec(jsonrpc=jsonrpc_request)
|
||||
|
||||
assert exc_info.value.passed == [error_eapi_response["error"]["data"][0]]
|
||||
assert exc_info.value.passed == [ERROR_EAPI_RESPONSE["error"]["data"][0]]
|
||||
assert exc_info.value.failed == "bad command"
|
||||
assert exc_info.value.errors == ["Invalid input (at token 1: 'bad')"]
|
||||
assert exc_info.value.errmsg == "CLI command 2 of 3 'bad command' failed: invalid command"
|
||||
|
@ -76,7 +77,7 @@ async def test_jsonrpc_exec_eapi_command_error(
|
|||
|
||||
async def test_jsonrpc_exec_http_status_error(asynceapi_device: Device, httpx_mock: HTTPXMock) -> None:
|
||||
"""Test the Device.jsonrpc_exec method with an HTTPStatusError."""
|
||||
jsonrpc_request: dict[str, Any] = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request = JSONRPC_REQUEST_TEMPLATE.copy()
|
||||
jsonrpc_request["params"]["cmds"] = ["show version"]
|
||||
|
||||
httpx_mock.add_response(status_code=500, text="Internal Server Error")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue